简介
如果你被分配到一个你不熟悉的项目,或者你找到了一个感兴趣的开放源代码项目,那么在开始修改代码之前,你需要先对代码库有一定了解。 本指南将介绍如何使用 GitHub Copilot Chat 来探索代码库并快速了解项目。
使用 Copilot 对话助手
在本指南中,我们将在 GitHub.com 上使用 Copilot 对话助手 的辅助模式进行操作。该模式会在 GitHub.com 当前页面的右下角显示一个 Copilot 对话助手 面板。
你可以通过单击并拖动面板边缘来展开 Copilot 对话助手 面板,以便为 Copilot 的回复提供更多显示空间。
使用预定义的提示
Copilot 对话助手 附带一组预定义提示,可帮助你快速开始代码库探索。 这些提示以按钮形式显示在聊天面板中, 当你使用 Copilot 对话助手 开始新的对话时即可看到。 提示选项会根据 GitHub.com 当前显示的页面而不同。
-
在 GitHub.com 上打开希望探索的仓库。
-
单击“Code”选项卡以显示仓库的主页****。
-
按 Shift+C,在辅助模式下打开 Copilot 对话助手。
-
单击聊天面板中的“Tell me about this repository”按钮****。
提示
如果未显示此按钮,请确保位于仓库的主页上,然后单击 Copilot 面板右上角的加号 (),以启动新对话。
系统会将预定义提示提交给 Copilot,然后聊天面板将显示答复。
-
你也可以在阅读完答复后,单击 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 帮助你了解目录中的文件或单个文件的用途。
了解目录中的文件:
- 导航到 GitHub.com 上的目录。
- 按 Shift+C,在辅助模式下打开 Copilot 对话助手。
- 询问 Copilot 以下问题:
Explain the files in this directory
。
了解某个具体文件:
- 在 GitHub.com 上打开该文件。
- 按 Shift+C,在辅助模式下打开 Copilot 对话助手。
- 对于小文件,请询问 Copilot 以下问题:
Explain this file
。 - 对于大型文件,请询问以下问题:
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.
理解特定代码行
使用 Copilot 帮助你理解文件中的特定代码行。
了解特定代码行:
- 在 GitHub 中,导航到一个存储库并打开一个文件。
- 通过单击要选择的第一行的行号,按住 Shift 并单击要选择的最后一行的行号来选择多行。
- 要询问有关所选行的问题,请单击所选内容右侧的 Copilot 图标 ()。 这将显示 GitHub Copilot Chat 面板,并将所选行作为问题的上下文。
- 要提出预定义的问题,请单击 Copilot 图标旁的向下按钮,然后选择其中一个选项。
- 如果单击了 Copilot 图标,请在聊天面板底部的提示框中键入问题,然后按 Enter。
理解特定的文件或符号
使用 Copilot 帮助你理解代码库中特定的文件或符号的用途。 符号是代码中的命名实体,如函数、类或变量。
-
导航到 GitHub 上的存储库。
-
单击 图标旁边的 ,然后单击“Assistive”以打开 Copilot 对话助手 面板********。
-
在提示框中,单击 Attach,然后单击“Files, folders, and symbols”********。
-
搜索并选择一个或多个文件、文件夹或符号。
-
在提示框中,键入问题,然后按 Enter。
Copilot 在聊天面板中回复。
提示
如果仓库的语义代码搜索索引是最新的,则 Copilot 在仓库上下文中回答类似这些自然语言问题的能力将得到优化。 有关详细信息,请参阅“为 Copilot 聊天编制存储库索引”。
了解提交
熟悉项目的一个好方法是查看最近的工作内容。 可以通过浏览最近的提交来执行此操作。
-
在 GitHub 上,导航到存储库的主页面。
-
在存储库的主页上的文件列表上方,单击 “提交”。
-
单击提交消息以显示该提交的差异视图。
-
在 Copilot 对话助手 面板中,输入
What does this commit do?
。 -
如有必要,可以输入
Explain in more detail
进行跟进。
使用“Insights”选项卡
除使用 Copilot 来帮助你熟悉项目之外,还可以使用 GitHub.com 上的“Insights”选项卡****。 该选项卡提供了仓库的大致概述。
有关详细信息,请参阅 使用 Pulse 查看存储库活动摘要 和 查看项目的贡献者。