Skip to main content

使用 Copilot 探索代码库

GitHub Copilot Chat 可以帮助你了解代码库的内容、结构和功能。

简介

如果你被分配到一个你不熟悉的项目,或者你找到了一个感兴趣的开放源代码项目,那么在开始修改代码之前,你需要先对代码库有一定了解。 本指南将介绍如何使用 GitHub Copilot Chat 来探索代码库并快速了解项目。

使用 Copilot Chat

在本指南中,我们将在 GitHub.com 上使用 Copilot Chat 的辅助模式进行操作。该模式会在 GitHub.com 当前页面的右下角显示一个 Copilot Chat 面板。

你可以通过单击并拖动面板边缘来展开 Copilot Chat 面板,以便为 Copilot 的回复提供更多显示空间。

使用预定义的提示

Copilot Chat 附带一组预定义提示,可帮助你快速开始代码库探索。 这些提示以按钮形式显示在聊天面板中, 当你使用 Copilot Chat 开始新的对话时即可看到。 提示选项会根据 GitHub.com 当前显示的页面而不同。

  1. 在 GitHub.com 上打开希望探索的仓库。

  2. 单击“Code”选项卡以显示仓库的主页****。

  3. Shift+C,在辅助模式下打开 Copilot Chat。

  4. 单击聊天面板中的“Tell me about this repository”按钮****。

    聊天面板的屏幕截图,其中突出显示了“Tell me about this repository”按钮。

    提示

    如果未显示此按钮,请确保位于仓库的主页上,然后单击 Copilot 面板右上角的加号 (),以启动新对话。

    系统会将预定义提示提交给 Copilot,然后聊天面板将显示答复。

  5. 你也可以在阅读完答复后,单击 Copilot 面板右上角的加号 () 启动新对话,然后单击“How to get started with this repository”****。

示例提示

以下提示是一些你可以向 Copilot 提出的问题示例,可以帮助你了解代码库。

一般问题

  • Based on the code in this repository, give me an overview of the architecture of the codebase. Provide evidence.

  • Which languages are used in this repo? Show the percentages for each language.

  • What are the core algorithms implemented in this repo?

  • What design patterns are used in this repository? Give a brief explanation of each pattern that you find, and an example of code from this repository that uses the pattern, with a link to the file.

具体问题

这些问题是否有用将取决于你要探索的代码库。

  • How do I build this project?

  • Where is authentication handled in this codebase?

  • Analyze the code in this repository and tell me about the entry points for this application.

  • Describe the data flow in this application.

  • Analyze the code in this repository and tell me what application-level security mechanisms are employed. Provide references.

了解目录中的文件

使用 Copilot 帮助你了解目录中的文件或单个文件的用途。

了解目录中的文件:

  1. 导航到 GitHub.com 上的目录。
  2. Shift+C,在辅助模式下打开 Copilot Chat。
  3. 询问 Copilot 以下问题:Explain the files in this directory

了解某个具体文件:

  1. 在 GitHub.com 上打开该文件。
  2. Shift+C,在辅助模式下打开 Copilot Chat。
  3. 对于小文件,请询问 Copilot 以下问题:Explain this file
  4. 对于大型文件,请询问以下问题:Explain what this file does. Start with an overview of the purpose of the file. Then, in appropriately headed sections, go through each part of the file and explain what it does in detail.

了解提交

熟悉项目的一个好方法是查看最近的工作内容。 可以通过浏览最近的提交来执行此操作。

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在存储库的主页上的文件列表上方,单击 “提交”。

    存储库的主页的屏幕截图。 时钟图标和“178 个提交”以橙色边框突出显示。

  3. 单击提交消息以显示该提交的差异视图。

  4. 在 Copilot Chat 面板中,输入 What does this commit do?

  5. 如有必要,可以输入 Explain in more detail 进行跟进。

使用“Insights”选项卡

除使用 Copilot 来帮助你熟悉项目之外,还可以使用 GitHub.com 上的“Insights”选项卡****。 该选项卡提供了仓库的大致概述。

有关详细信息,请参阅 使用 Pulse 查看存储库活动摘要查看项目的贡献者

其他阅读材料