简介
如果你被分配到一个不熟悉的project工作,或者你找到了一个感兴趣的开放源代码 project,你想参与其中,则需要对代码库有一些了解,然后才能开始进行更改。 本指南将介绍如何用于 GitHub Copilot 聊天功能 浏览基本代码并快速了解项目。
使用 副驾驶聊天
在本指南中,我们将在 副驾驶聊天 上使用 GitHub.com,你可以在 github.com/copilot 找到它。
提供存储库上下文
可以通过以下任一方式询问 副驾驶聊天 代码库。
在聊天中附加存储库
附加存储库可提供 副驾驶聊天 对存储库中的代码的访问权限,并且最好是在聊天期间比较或切换存储库。
- 打开 GitHub,导航到 github.com/copilot。
- 在文本框中,单击“ 添加存储库”、“文件和空格”,然后单击“ 存储库”。
- 搜索并选择要浏览的存储库。
从存储库页面提问
注意
此功能当前处于 公开预览,并可能会发生更改。
可以直接从其页面上副驾驶聊天询问GitHub存储库,而无需先附加它。 这是一种快速熟悉你之前未接触过的项目的方法。
- 打开 GitHub,导航到要浏览的存储库。
- 从存储库页面打开 副驾驶聊天 并提出问题。 Copilot 使用存储库作为上下文,并在存储库的实际文件和符号中为其答案提供依据。
- 请基于相同的共享上下文,提出一个后续问题,以进一步深入探讨。
示例提示
以下提示是可请求 Copilot 的问题类型的示例,可帮助你了解基本代码。
一般问题
-
Based on the code in this repository, give me an overview of the architecture of the codebase. Provide evidence. -
Give me an overview of this repository: its purpose, structure, key components, and how to run it. -
What are the main entry points and how do the key components fit together? -
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 上,导航到存储库的主页面。
-
在存储库的主页上的文件列表上方,单击“ commits”****。

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