简介
如果你被分配到一个不熟悉的project工作,或者你找到了一个感兴趣的open source project,你想参与其中,则需要对代码库有一些了解,然后才能开始进行更改。 本指南将介绍如何使用 GitHub Copilot 聊天功能 浏览代码库并快速了解项目。
使用 副驾驶聊天
在本指南的整个过程中,我们将在 副驾驶聊天 上使用 GitHub.com,您可以在 github.com/copilot 找到。
连接代码库
在 副驾驶聊天 帮助您之前,您需要附加想要浏览的代码库。
- 在 GitHub上,导航到 github.com/copilot。
- 在文本框中,单击 添加存储库、文件和空格,然后单击“ 存储库”。
- 搜索并选择要浏览的存储库。
副驾驶聊天 现在已访问该代码库,您可以开始询问相关问题。
示例提示
以下提示是一些您可以向 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 上的目录。
-
在页面右上角,单击 Copilot 图标(),打开 副驾驶聊天。
Copilot 会将目录内容作为您提问的上下文。
-
询问 Copilot:
Explain the files in this directory。
了解某个具体文件:
-
在 GitHub.com 上打开该文件。
-
在页面右上角,单击 Copilot 图标(),打开 副驾驶聊天。
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 聊天功能 面板,并将所选行作为问题的上下文。
-
要提出预定义的问题,请单击 Copilot 图标旁的向下按钮,然后选择其中一个选项。

-
如果单击了 Copilot 图标,请在聊天面板底部的提示框中键入问题,然后按 Enter。
理解特定的文件或符号
使用 Copilot 帮助你理解代码库中特定的文件或符号的用途。 符号是代码中的命名实体,如函数、类或变量。
-
在 GitHub上,导航到存储库并打开文件。
-
在文件顶部,点击 Copilot 图标(),以打开 副驾驶聊天。
Copilot 将显示分屏中的文件内容作为问题上下文。
-
如果要询问特定符号,请在文件中突出显示该符号。
-
在提示框中,键入有关文件或突出显示符号的问题,然后按 Enter。
Copilot 在聊天面板中回复。
提示
如果仓库的语义代码搜索索引是最新的,则 Copilot 在仓库上下文中回答类似这些自然语言问题的能力将得到优化。 有关详细信息,请参阅“为GitHub Copilot编制存储库索引”。
了解提交
熟悉一个项目的好方法是查看最近完成的工作。 您可以通过浏览最近的提交来执行此操作。
-
在 GitHub 上,导航到存储库的主页面。1. 在存储库的主页上的文件列表上方,单击“ commits”****。

-
单击提交消息以显示该提交的差异视图。
-
在 副驾驶聊天 面板中,输入
What does this commit do?。 -
如有必要,可以输入
Explain in more detail进行跟进。
使用“Insights”选项卡
除了使用Copilot来帮助你熟悉项目之外,还可以使用GitHub.com上的Insights选项卡。 它提供了仓库的大致概述。
有关详细信息,请参阅 使用 Pulse 查看存储库活动摘要 和 查看项目的贡献者。