本文档版本适用于在 GitHub 网站上使用仓库自定义指令。点击上方选项卡可查看在其他环境中自定义指令的信息。
简介
仓库自定义指令允许您为 Copilot 提供仓库特定的指导和偏好。有关更多信息,请参阅关于自定义 GitHub Copilot 响应。
仓库自定义指令的先决条件
-
您必须有一个自定义指令文件(请参阅以下说明)。
-
对于 Copilot 代码审查,您个人选择是否使用自定义指令必须设置为启用。此功能默认启用。请参阅本文档后面的启用或禁用仓库自定义指令。
创建自定义指令
GitHub 上的 Copilot 支持三种类型的仓库自定义指令。有关哪些 GitHub Copilot 功能支持这些类型指令的详细信息,请参阅关于自定义 GitHub Copilot 响应。
-
仓库范围的自定义指令适用于在仓库上下文中发出的所有请求。
这些指令在仓库的
.github目录中的copilot-instructions.md文件中指定。请参阅创建仓库范围的自定义指令。 -
特定路径的自定义指令适用于在与指定路径匹配的文件上下文中发出的请求。
这些指令在一个或多个
NAME.instructions.md文件中指定,这些文件位于仓库的.github/instructions目录内或其下方。请参阅创建特定路径的自定义指令。如果您指定的路径与 Copilot 正在处理的文件匹配,并且仓库范围的自定义指令文件也存在,那么将同时使用这两个文件中的指令。
-
代理指令由 AI 代理使用。
您可以创建包含一个或多个
AGENTS.md文件,存储在仓库的任何位置。当 Copilot 工作时,目录树中最接近的AGENTS.md文件将优先。有关更多信息,请参阅 agentsmd/agents.md 仓库。或者,您可以使用存储在仓库根目录中的单个
CLAUDE.md或GEMINI.md文件。
创建仓库范围的自定义指令
您可以从头开始创建自己的自定义指令文件。请参阅编写您自己的 copilot-instructions.md 文件。或者,您可以要求 Copilot 云代理为您生成一个。
要求 Copilot 云代理生成一个 copilot-instructions.md 文件
-
导航到 github.com/copilot/agents 上的代理选项卡。
您也可以通过点击 GitHub 任何页面上搜索栏旁边的 按钮,然后从侧边栏中选择 Agents(代理)。
-
使用提示字段中的下拉菜单,选择您希望 Copilot 为其生成自定义指令的仓库。
-
复制以下提示并将其粘贴到提示字段中,如果需要,请自定义它
Markdown Your task is to "onboard" this repository to Copilot cloud agent by adding a .github/copilot-instructions.md file in the repository that contains information describing how a cloud agent seeing it for the first time can work most efficiently. You will do this task only one time per repository and doing a good job can SIGNIFICANTLY improve the quality of the agent's work, so take your time, think carefully, and search thoroughly before writing the instructions. <Goals> - Reduce the likelihood of a cloud agent pull request getting rejected by the user due to generating code that fails the continuous integration build, fails a validation pipeline, or having misbehavior. - Minimize bash command and build failures. - Allow the agent to complete its task more quickly by minimizing the need for exploration using grep, find, str_replace_editor, and code search tools. </Goals> <Limitations> - Instructions must be no longer than 2 pages. - Instructions must not be task specific. </Limitations> <WhatToAdd> Add the following high level details about the codebase to reduce the amount of searching the agent has to do to understand the codebase each time: <HighLevelDetails> - A summary of what the repository does. - High level repository information, such as the size of the repo, the type of the project, the languages, frameworks, or target runtimes in use. </HighLevelDetails> Add information about how to build and validate changes so the agent does not need to search and find it each time. <BuildInstructions> - For each of bootstrap, build, test, run, lint, and any other scripted step, document the sequence of steps to take to run it successfully as well as the versions of any runtime or build tools used. - Each command should be validated by running it to ensure that it works correctly as well as any preconditions and postconditions. - Try cleaning the repo and environment and running commands in different orders and document errors and misbehavior observed as well as any steps used to mitigate the problem. - Run the tests and document the order of steps required to run the tests. - Make a change to the codebase. Document any unexpected build issues as well as the workarounds. - Document environment setup steps that seem optional but that you have validated are actually required. - Document the time required for commands that failed due to timing out. - When you find a sequence of commands that work for a particular purpose, document them in detail. - Use language to indicate when something should always be done. For example: "always run npm install before building". - Record any validation steps from documentation. </BuildInstructions> List key facts about the layout and architecture of the codebase to help the agent find where to make changes with minimal searching. <ProjectLayout> - A description of the major architectural elements of the project, including the relative paths to the main project files, the location of configuration files for linting, compilation, testing, and preferences. - A description of the checks run prior to check in, including any GitHub workflows, continuous integration builds, or other validation pipelines. - Document the steps so that the agent can replicate these itself. - Any explicit validation steps that the agent can consider to have further confidence in its changes. - Dependencies that aren't obvious from the layout or file structure. - Finally, fill in any remaining space with detailed lists of the following, in order of priority: the list of files in the repo root, the contents of the README, the contents of any key source files, the list of files in the next level down of directories, giving priority to the more structurally important and snippets of code from key source files, such as the one containing the main method. </ProjectLayout> </WhatToAdd> <StepsToFollow> - Perform a comprehensive inventory of the codebase. Search for and view: - README.md, CONTRIBUTING.md, and all other documentation files. - Search the codebase for build steps and indications of workarounds like 'HACK', 'TODO', etc. - All scripts, particularly those pertaining to build and repo or environment setup. - All build and actions pipelines. - All project files. - All configuration and linting files. - For each file: - think: are the contents or the existence of the file information that the cloud agent will need to implement, build, test, validate, or demo a code change? - If yes: - Document the command or information in detail. - Explicitly indicate which commands work and which do not and the order in which commands should be run. - Document any errors encountered as well as the steps taken to workaround them. - Document any other steps or information that the agent can use to reduce time spent exploring or trying and failing to run bash commands. - Finally, explicitly instruct the agent to trust the instructions and only perform a search if the information in the instructions is incomplete or found to be in error. </StepsToFollow> - Document any errors encountered as well as the steps taken to work-around them.
Your task is to "onboard" this repository to Copilot cloud agent by adding a .github/copilot-instructions.md file in the repository that contains information describing how a cloud agent seeing it for the first time can work most efficiently. You will do this task only one time per repository and doing a good job can SIGNIFICANTLY improve the quality of the agent's work, so take your time, think carefully, and search thoroughly before writing the instructions. <Goals> - Reduce the likelihood of a cloud agent pull request getting rejected by the user due to generating code that fails the continuous integration build, fails a validation pipeline, or having misbehavior. - Minimize bash command and build failures. - Allow the agent to complete its task more quickly by minimizing the need for exploration using grep, find, str_replace_editor, and code search tools. </Goals> <Limitations> - Instructions must be no longer than 2 pages. - Instructions must not be task specific. </Limitations> <WhatToAdd> Add the following high level details about the codebase to reduce the amount of searching the agent has to do to understand the codebase each time: <HighLevelDetails> - A summary of what the repository does. - High level repository information, such as the size of the repo, the type of the project, the languages, frameworks, or target runtimes in use. </HighLevelDetails> Add information about how to build and validate changes so the agent does not need to search and find it each time. <BuildInstructions> - For each of bootstrap, build, test, run, lint, and any other scripted step, document the sequence of steps to take to run it successfully as well as the versions of any runtime or build tools used. - Each command should be validated by running it to ensure that it works correctly as well as any preconditions and postconditions. - Try cleaning the repo and environment and running commands in different orders and document errors and misbehavior observed as well as any steps used to mitigate the problem. - Run the tests and document the order of steps required to run the tests. - Make a change to the codebase. Document any unexpected build issues as well as the workarounds. - Document environment setup steps that seem optional but that you have validated are actually required. - Document the time required for commands that failed due to timing out. - When you find a sequence of commands that work for a particular purpose, document them in detail. - Use language to indicate when something should always be done. For example: "always run npm install before building". - Record any validation steps from documentation. </BuildInstructions> List key facts about the layout and architecture of the codebase to help the agent find where to make changes with minimal searching. <ProjectLayout> - A description of the major architectural elements of the project, including the relative paths to the main project files, the location of configuration files for linting, compilation, testing, and preferences. - A description of the checks run prior to check in, including any GitHub workflows, continuous integration builds, or other validation pipelines. - Document the steps so that the agent can replicate these itself. - Any explicit validation steps that the agent can consider to have further confidence in its changes. - Dependencies that aren't obvious from the layout or file structure. - Finally, fill in any remaining space with detailed lists of the following, in order of priority: the list of files in the repo root, the contents of the README, the contents of any key source files, the list of files in the next level down of directories, giving priority to the more structurally important and snippets of code from key source files, such as the one containing the main method. </ProjectLayout> </WhatToAdd> <StepsToFollow> - Perform a comprehensive inventory of the codebase. Search for and view: - README.md, CONTRIBUTING.md, and all other documentation files. - Search the codebase for build steps and indications of workarounds like 'HACK', 'TODO', etc. - All scripts, particularly those pertaining to build and repo or environment setup. - All build and actions pipelines. - All project files. - All configuration and linting files. - For each file: - think: are the contents or the existence of the file information that the cloud agent will need to implement, build, test, validate, or demo a code change? - If yes: - Document the command or information in detail. - Explicitly indicate which commands work and which do not and the order in which commands should be run. - Document any errors encountered as well as the steps taken to workaround them. - Document any other steps or information that the agent can use to reduce time spent exploring or trying and failing to run bash commands. - Finally, explicitly instruct the agent to trust the instructions and only perform a search if the information in the instructions is incomplete or found to be in error. </StepsToFollow> - Document any errors encountered as well as the steps taken to work-around them. -
点击 或按 Enter。
Copilot 将启动一个新会话,该会话将显示在提示框下方的列表中。Copilot 将创建一个草稿拉取请求,编写您的自定义指令,将其推送到分支,然后在完成后将您添加为审查者,从而触发通知。
编写您自己的 copilot-instructions.md 文件
-
在仓库的根目录中,创建一个名为
.github/copilot-instructions.md的文件。如果
.github目录尚不存在,请创建它。 -
以 Markdown 格式向文件中添加自然语言指令。
指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
提示
您第一次使用 Copilot 云代理在给定仓库中创建拉取请求时,Copilot 将留下一个评论,其中包含一个自动为仓库生成自定义指令的链接。
创建特定路径的自定义指令
注意
目前,在 GitHub.com 上,特定路径的自定义指令仅支持 Copilot 云代理和 Copilot 代码审查。
-
如果
.github/instructions目录尚不存在,请创建它。 -
可选地,创建
.github/instructions的子目录来组织您的指令文件。 -
创建一个或多个
NAME.instructions.md文件,其中NAME指示指令的目的。文件名必须以.instructions.md结尾。 -
在文件的开头,创建一个包含
applyTo关键字的 frontmatter 块。使用 glob 语法指定指令应用于哪些文件或目录。例如
--- applyTo: "app/models/**/*.rb" ---您可以通过逗号分隔多个模式。例如,要将指令应用于仓库中的所有 TypeScript 文件,可以使用以下 frontmatter 块
--- applyTo: "**/*.ts,**/*.tsx" ---Glob 示例
*- 将匹配当前目录中的所有文件。**或**/*- 将匹配所有目录中的所有文件。*.py- 将匹配当前目录中的所有.py文件。**/*.py- 将递归匹配所有目录中的所有.py文件。src/*.py- 将匹配src目录中的所有.py文件。例如,src/foo.py和src/bar.py,但**不**匹配src/foo/bar.py。src/**/*.py- 将递归匹配src目录中的所有.py文件。例如,src/foo.py、src/foo/bar.py和src/foo/bar/baz.py。**/subdir/**/*.py- 将递归匹配任何深度下的任何subdir目录中的所有.py文件。例如,subdir/foo.py、subdir/nested/bar.py、parent/subdir/baz.py和deep/parent/subdir/nested/qux.py,但**不**匹配不包含subdir目录的路径中的foo.py。
-
可选地,为了防止文件被 Copilot 云代理或 Copilot 代码审查使用,请在 frontmatter 块中添加
excludeAgent关键字。使用"code-review"或"cloud-agent"。例如,以下文件将仅由 Copilot 云代理读取。
--- applyTo: "**" excludeAgent: "code-review" ---如果 frontmatter 块中未包含
excludeAgent关键字,Copilot 代码审查和 Copilot 云代理都将使用您的指令。 -
使用 Markdown 格式添加您的自然语言自定义指令。指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
正在使用的自定义指令
文件中的指令在您保存文件后即可供 Copilot 使用。指令会自动添加到您提交给 Copilot 的请求中。
在 Copilot Chat (github.com/copilot) 中,您可以通过将包含指令文件的仓库作为附件添加,来开始使用仓库自定义指令的对话。
每当 Copilot Chat 使用仓库自定义指令时,指令文件都会作为生成响应的参考添加。要查明是否使用了仓库自定义指令,请展开聊天面板中聊天响应顶部的参考列表,并检查是否列出了 .github/copilot-instructions.md 文件。

您可以点击参考打开文件。
注意
- 多种类型的自定义指令可以应用于发送给 Copilot 的请求。个人指令优先级最高,其次是仓库指令,组织指令优先级最低。但是,所有相关的指令集都会提供给 Copilot。
- 尽可能避免提供相互冲突的指令集。如果您担心响应质量,可以暂时禁用仓库指令。请参阅为 GitHub Copilot 添加仓库自定义指令。
为 Copilot 代码审查启用或禁用自定义指令
Copilot 代码审查默认启用自定义指令,但您可以在 GitHub.com 上的仓库设置中禁用或重新启用它们。这适用于 Copilot 在此仓库中执行的所有代码审查对自定义指令的使用。
-
在 GitHub 上,导航至仓库的主页面。
-
在仓库名称下方,点击 设置。如果您看不到“设置”选项卡,请选择 下拉菜单,然后点击 设置。

-
在侧边栏的“代码与自动化”部分,点击 Copilot,然后点击 代码审查。
-
打开或关闭“审查拉取请求时使用自定义指令”选项。
注意
审查拉取请求时,Copilot 使用拉取请求基础分支中的自定义指令。例如,如果您的拉取请求旨在将 my-feature-branch 合并到 main 中,则 Copilot 将使用 main 中的自定义指令。
延伸阅读
本文版本介绍如何在 VS Code 中使用仓库自定义指令和提示文件。点击上方选项卡可查看在其他环境中自定义指令的信息。
简介
仓库自定义指令允许您为 Copilot 提供仓库特定的指导和偏好。有关更多信息,请参阅关于自定义 GitHub Copilot 响应。
仓库自定义指令的先决条件
-
您必须有一个自定义指令文件(请参阅以下说明)。
-
自定义指令必须启用。此功能默认启用。请参阅本文档后面的启用或禁用仓库自定义指令。
创建自定义指令
VS Code 支持三种类型的仓库自定义指令。有关 GitHub Copilot 哪些功能支持这些类型指令的详细信息,请参阅关于自定义 GitHub Copilot 响应。
-
仓库范围的自定义指令,适用于在仓库上下文中发出的所有请求。
这些指令在仓库的
.github目录中的copilot-instructions.md文件中指定。请参阅创建仓库范围的自定义指令。 -
特定路径的自定义指令,适用于在与指定路径匹配的文件上下文中发出的请求。
这些指令在一个或多个
NAME.instructions.md文件中指定,这些文件位于仓库的.github/instructions目录内或其下方。请参阅创建特定路径的自定义指令。如果您指定的路径与 Copilot 正在处理的文件匹配,并且仓库范围的自定义指令文件也存在,那么将同时使用这两个文件中的指令。
-
代理指令由 AI 代理使用。
您可以创建包含一个或多个
AGENTS.md文件,存储在仓库的任何位置。当 Copilot 工作时,目录树中最接近的AGENTS.md文件将优先。有关更多信息,请参阅 agentsmd/agents.md 仓库。注意
默认情况下,工作区根目录之外的
AGENTS.md文件支持目前已关闭。有关如何启用此功能的详细信息,请参阅 VS Code 文档中的在 VS Code 中使用自定义指令。
创建仓库范围的自定义指令
-
在仓库的根目录中,创建一个名为
.github/copilot-instructions.md的文件。如果
.github目录尚不存在,请创建它。 -
以 Markdown 格式向文件中添加自然语言指令。
指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
创建特定路径的自定义指令
-
如果
.github/instructions目录尚不存在,请创建它。 -
可选地,创建
.github/instructions的子目录来组织您的指令文件。 -
创建一个或多个
NAME.instructions.md文件,其中NAME指示指令的目的。文件名必须以.instructions.md结尾。 -
在文件的开头,创建一个包含
applyTo关键字的 frontmatter 块。使用 glob 语法指定指令应用于哪些文件或目录。例如
--- applyTo: "app/models/**/*.rb" ---您可以通过逗号分隔多个模式。例如,要将指令应用于仓库中的所有 TypeScript 文件,可以使用以下 frontmatter 块
--- applyTo: "**/*.ts,**/*.tsx" ---Glob 示例
*- 将匹配当前目录中的所有文件。**或**/*- 将匹配所有目录中的所有文件。*.py- 将匹配当前目录中的所有.py文件。**/*.py- 将递归匹配所有目录中的所有.py文件。src/*.py- 将匹配src目录中的所有.py文件。例如,src/foo.py和src/bar.py,但**不**匹配src/foo/bar.py。src/**/*.py- 将递归匹配src目录中的所有.py文件。例如,src/foo.py、src/foo/bar.py和src/foo/bar/baz.py。**/subdir/**/*.py- 将递归匹配任何深度下的任何subdir目录中的所有.py文件。例如,subdir/foo.py、subdir/nested/bar.py、parent/subdir/baz.py和deep/parent/subdir/nested/qux.py,但**不**匹配不包含subdir目录的路径中的foo.py。
-
可选地,为了防止文件被 Copilot 云代理或 Copilot 代码审查使用,请在 frontmatter 块中添加
excludeAgent关键字。使用"code-review"或"cloud-agent"。例如,以下文件将仅由 Copilot 云代理读取。
--- applyTo: "**" excludeAgent: "code-review" ---如果 frontmatter 块中未包含
excludeAgent关键字,Copilot 代码审查和 Copilot 云代理都将使用您的指令。 -
使用 Markdown 格式添加您的自然语言自定义指令。指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
正在使用的自定义指令
文件中的指令在您保存文件后即可供 Copilot 使用。指令会自动添加到您提交给 Copilot 的请求中。
自定义指令在聊天视图或行内聊天中不可见,但您可以通过查看聊天视图中响应的“引用”列表来验证它们是否正在被 Copilot 使用。如果自定义指令已添加到发送给模型的提示中,则 .github/copilot-instructions.md 文件将列为引用。您可以点击引用打开文件。

启用或禁用仓库自定义指令
您可以选择是否让 Copilot 使用基于仓库的自定义指令。
启用或禁用 Copilot Chat 的自定义指令
Copilot Chat 默认启用自定义指令,但您可以随时禁用或重新启用它们。这适用于您自己使用 Copilot Chat,不影响其他用户。
- 使用键盘快捷键 Command+, (Mac) / Ctrl+, (Linux/Windows) 打开设置编辑器。
- 在搜索框中键入
instruction file。 - 勾选或清除 Code Generation: Use Instruction Files(代码生成:使用指令文件) 下方的复选框。
为 Copilot 代码审查启用或禁用自定义指令
Copilot 代码审查默认启用自定义指令,但您可以在 GitHub.com 上的仓库设置中禁用或重新启用它们。这适用于 Copilot 在此仓库中执行的所有代码审查对自定义指令的使用。
-
在 GitHub 上,导航至仓库的主页面。
-
在仓库名称下方,点击 设置。如果您看不到“设置”选项卡,请选择 下拉菜单,然后点击 设置。

-
在侧边栏的“代码与自动化”部分,点击 Copilot,然后点击 代码审查。
-
打开或关闭“审查拉取请求时使用自定义指令”选项。
启用和使用提示文件
注意
- Copilot 提示文件目前处于公共预览阶段,可能会有所更改。提示文件仅在 VS Code、Visual Studio 和 JetBrains IDE 中可用。请参阅关于自定义 GitHub Copilot 响应。
- 有关特定语言和场景的社区贡献提示文件示例,请参阅 Awesome GitHub Copilot Customizations 仓库。
提示文件让您能够构建和共享可重用的提示指令以及额外上下文。提示文件是存储在工作区中的 Markdown 文件,它模仿 Copilot Chat 中现有的提示编写格式(例如,Rewrite #file:x.ts)。您可以在工作区中拥有多个提示文件,每个文件定义一个用于不同目的的提示。
启用提示文件
要启用提示文件,请配置工作区设置。
- 按 Ctrl+Shift+P (Windows/Linux) / Command+Shift+P (Mac) 打开命令面板。
- 键入“Open Workspace Settings (JSON)”并选择显示的选项。
- 在
settings.json文件中,添加"chat.promptFiles": true以启用.github/prompts文件夹作为提示文件的位置。如果此文件夹尚不存在,则会创建它。
创建提示文件
-
按 Ctrl+Shift+P (Windows/Linux) / Command+Shift+P (Mac) 打开命令面板。
-
键入“prompt”并选择 Chat: Create Prompt(聊天:创建提示)。
-
输入提示文件的名称,不包括
.prompt.md文件扩展名。名称可以包含字母数字字符和空格,并应描述文件将包含的提示信息的目的。 -
使用 Markdown 格式编写提示指令。
您可以使用 Markdown 链接(例如,
[index](../../web/index.ts))或使用#file:../../web/index.ts语法引用工作区中的其他文件。路径是相对于提示文件的。引用其他文件允许您提供额外的上下文,例如 API 规范或产品文档。
使用提示文件
-
在 Copilot Chat 视图底部,点击 附加上下文 图标().
-
在下拉菜单中,点击 提示... 并选择您要使用的提示文件。
-
可选地,附加其他文件,包括提示文件,以提供更多上下文。
-
可选地,在聊天提示框中输入额外信息。
您是否需要这样做取决于您使用的提示内容。
-
提交聊天提示。
有关提示文件的更多信息,请参阅 Visual Studio Code 文档中的在 Visual Studio Code 中使用提示文件。
延伸阅读
本文版本介绍如何在 Visual Studio 中使用仓库自定义指令和提示文件。点击上方选项卡可查看在其他环境中自定义指令的信息。
简介
仓库自定义指令允许您为 Copilot 提供仓库特定的指导和偏好。有关更多信息,请参阅关于自定义 GitHub Copilot 响应。
仓库自定义指令的先决条件
-
您必须有一个自定义指令文件(请参阅以下说明)。
-
必须在您的设置中启用 Enable custom instructions...(启用自定义指令...) 选项。此功能默认启用。请参阅本文档后面的启用或禁用仓库自定义指令。
创建自定义指令
Visual Studio 支持两种自定义指令。有关 GitHub Copilot 哪些功能支持这些类型指令的详细信息,请参阅关于自定义 GitHub Copilot 响应。
-
仓库范围的自定义指令,适用于在仓库上下文中发出的所有请求。
这些指令在仓库的
.github目录中的copilot-instructions.md文件中指定。请参阅创建仓库范围的自定义指令。 -
特定路径的自定义指令,适用于在与指定路径匹配的文件上下文中发出的请求。
这些指令在一个或多个
NAME.instructions.md文件中指定,这些文件位于仓库的.github/instructions目录内或其下方。请参阅创建特定路径的自定义指令。如果您指定的路径与 Copilot 正在处理的文件匹配,并且仓库范围的自定义指令文件也存在,那么将同时使用这两个文件中的指令。
创建仓库范围的自定义指令
-
在仓库的根目录中,创建一个名为
.github/copilot-instructions.md的文件。如果
.github目录尚不存在,请创建它。 -
以 Markdown 格式向文件中添加自然语言指令。
指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
创建特定路径的自定义指令
-
如果
.github/instructions目录尚不存在,请创建它。 -
可选地,创建
.github/instructions的子目录来组织您的指令文件。 -
创建一个或多个
NAME.instructions.md文件,其中NAME指示指令的目的。文件名必须以.instructions.md结尾。 -
在文件的开头,创建一个包含
applyTo关键字的 frontmatter 块。使用 glob 语法指定指令应用于哪些文件或目录。例如
--- applyTo: "app/models/**/*.rb" ---您可以通过逗号分隔多个模式。例如,要将指令应用于仓库中的所有 TypeScript 文件,可以使用以下 frontmatter 块
--- applyTo: "**/*.ts,**/*.tsx" ---Glob 示例
*- 将匹配当前目录中的所有文件。**或**/*- 将匹配所有目录中的所有文件。*.py- 将匹配当前目录中的所有.py文件。**/*.py- 将递归匹配所有目录中的所有.py文件。src/*.py- 将匹配src目录中的所有.py文件。例如,src/foo.py和src/bar.py,但**不**匹配src/foo/bar.py。src/**/*.py- 将递归匹配src目录中的所有.py文件。例如,src/foo.py、src/foo/bar.py和src/foo/bar/baz.py。**/subdir/**/*.py- 将递归匹配任何深度下的任何subdir目录中的所有.py文件。例如,subdir/foo.py、subdir/nested/bar.py、parent/subdir/baz.py和deep/parent/subdir/nested/qux.py,但**不**匹配不包含subdir目录的路径中的foo.py。
-
可选地,为了防止文件被 Copilot 云代理或 Copilot 代码审查使用,请在 frontmatter 块中添加
excludeAgent关键字。使用"code-review"或"cloud-agent"。例如,以下文件将仅由 Copilot 云代理读取。
--- applyTo: "**" excludeAgent: "code-review" ---如果 frontmatter 块中未包含
excludeAgent关键字,Copilot 代码审查和 Copilot 云代理都将使用您的指令。 -
使用 Markdown 格式添加您的自然语言自定义指令。指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
正在使用的自定义指令
文件中的指令在您保存文件后即可供 Copilot 使用。指令会自动添加到您提交给 Copilot 的请求中。
自定义指令在聊天视图或行内聊天中不可见,但您可以通过查看聊天视图中响应的“引用”列表来验证它们是否正在被 Copilot 使用。如果自定义指令已添加到发送给模型的提示中,则 .github/copilot-instructions.md 文件将列为引用。您可以点击引用打开文件。

启用或禁用仓库自定义指令
您可以选择是否让 Copilot 使用基于仓库的自定义指令。
启用或禁用 Copilot Chat 的自定义指令
Copilot Chat 默认启用自定义指令,但您可以随时禁用或重新启用它们。这适用于您自己使用 Copilot Chat,不影响其他用户。
-
在 Visual Studio 菜单栏中,在 工具 下,点击 选项。

-
在“选项”对话框中,在搜索框中键入
custom instructions,然后点击 Copilot。 -
勾选或清除 启用从 .github/copilot-instructions.md 文件加载自定义指令并将其添加到请求 的复选框。

为 Copilot 代码审查启用或禁用自定义指令
Copilot 代码审查默认启用自定义指令,但您可以在 GitHub.com 上的仓库设置中禁用或重新启用它们。这适用于 Copilot 在此仓库中执行的所有代码审查对自定义指令的使用。
-
在 GitHub 上,导航至仓库的主页面。
-
在仓库名称下方,点击 设置。如果您看不到“设置”选项卡,请选择 下拉菜单,然后点击 设置。

-
在侧边栏的“代码与自动化”部分,点击 Copilot,然后点击 代码审查。
-
打开或关闭“审查拉取请求时使用自定义指令”选项。
使用提示文件
注意
- Copilot 提示文件目前处于公共预览阶段,可能会有所更改。提示文件仅在 VS Code、Visual Studio 和 JetBrains IDE 中可用。请参阅关于自定义 GitHub Copilot 响应。
- 有关特定语言和场景的社区贡献提示文件示例,请参阅 Awesome GitHub Copilot Customizations 仓库。
提示文件让您能够构建和共享可重用的提示指令以及额外上下文。提示文件是存储在工作区中的 Markdown 文件,它模仿 Copilot Chat 中现有的提示编写格式(例如,Rewrite #file:x.ts)。您可以在工作区中拥有多个提示文件,每个文件定义一个用于不同目的的提示。
创建提示文件
-
在仓库根目录的
.github/prompts文件夹中添加一个提示文件,包括.prompt.md文件扩展名。名称可以包含字母数字字符和空格,并应描述文件将包含的提示信息的目的。 -
使用 Markdown 格式编写提示指令。
您可以使用 Markdown 链接(例如,
[index](../../web/index.ts))或使用#file:'../../web/index.ts'语法引用工作区中的其他文件。路径是相对于提示文件的。引用其他文件允许您提供额外的上下文,例如 API 规范或产品文档。
有关提示文件的更多信息,请参阅 Visual Studio 文档中的在 Visual Studio 中使用提示文件。
延伸阅读
本文版本介绍如何在 JetBrains IDE 中使用仓库自定义指令。点击上方选项卡可查看在其他环境中自定义指令的信息。
简介
仓库自定义指令允许您为 Copilot 提供仓库特定的指导和偏好。有关更多信息,请参阅关于自定义 GitHub Copilot 响应。
仓库自定义指令的先决条件
-
您必须有一个自定义指令文件(请参阅以下说明)。
-
您的 JetBrains IDE 中必须安装最新版本的 Copilot 扩展。
创建自定义指令
JetBrains IDE 支持存储在仓库中的单个 .github/copilot-instructions.md 自定义指令文件和本地存储的 global-copilot-instructions.md 文件。
您可以使用 Copilot 设置页面在仓库中创建 .github/copilot-instructions.md 文件,或者您可以手动创建文件。
指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
使用设置页面
- 在您的 JetBrains IDE 中,点击 文件 菜单 (Windows),或菜单栏中应用程序的名称 (macOS),然后点击 设置。
- 在左侧侧边栏中点击 工具,点击 GitHub Copilot,然后点击 自定义。
- 在“Copilot 指令”下,点击 工作区 或 全局,选择自定义指令适用于当前工作区还是所有工作区。
手动创建工作区自定义指令文件
-
在仓库的根目录中,创建一个名为
.github/copilot-instructions.md的文件。如果
.github目录尚不存在,请创建它。 -
以 Markdown 格式向文件中添加自然语言指令。
保存后,这些指令将应用于您在启用 Copilot 的情况下打开的 JetBrains IDE 中的当前工作区。
手动创建全局自定义指令文件
要在所有 JetBrains IDE 工作区中应用相同的指令,您可以在本地机器上创建一个全局自定义指令文件。
-
打开您的文件浏览器或终端。
-
导航到适用于您操作系统的相应位置
- macOS:
/Users/您的用户名/.config/github-copilot/intellij/ - Windows:
C:\Users\您的用户名\AppData\Local\github-copilot\intellij\
- macOS:
-
在该目录中创建一个名为
global-copilot-instructions.md的文件。 -
使用 Markdown 格式添加您的自然语言自定义指令。
保存后,这些指令将全局应用于您在启用 Copilot 的情况下打开的 JetBrains IDE 中的所有工作区。
正在使用的自定义指令
文件中的指令在您保存文件后即可供 Copilot 使用。指令会自动添加到您提交给 Copilot 的请求中。
自定义指令在聊天视图或行内聊天中不可见,但您可以通过查看聊天视图中响应的“引用”列表来验证它们是否正在被 Copilot 使用。如果自定义指令已添加到发送给模型的提示中,则 .github/copilot-instructions.md 文件将列为引用。您可以点击引用打开文件。
使用提示文件
注意
- Copilot 提示文件目前处于公共预览阶段,可能会有所更改。提示文件仅在 VS Code、Visual Studio 和 JetBrains IDE 中可用。请参阅关于自定义 GitHub Copilot 响应。
- 有关特定语言和场景的社区贡献提示文件示例,请参阅 Awesome GitHub Copilot Customizations 仓库。
提示文件让您能够构建和共享可重用的提示指令以及额外上下文。提示文件是存储在工作区中的 Markdown 文件,它模仿 Copilot Chat 中现有的提示编写格式(例如,Rewrite #file:x.ts)。您可以在工作区中拥有多个提示文件,每个文件定义一个用于不同目的的提示。
编写提示指令时,您可以使用 Markdown 链接(例如,[index](../../web/index.ts))或使用 #file:../../web/index.ts 语法引用工作区中的其他文件。路径是相对于提示文件的。引用其他文件允许您提供额外的上下文,例如 API 规范或产品文档。
提示文件保存后,其指令将应用于您在启用 Copilot 的情况下打开的 JetBrains IDE 中的当前工作区。
使用命令行创建提示文件
- 如果您的工作区中尚不存在
.github/prompts目录,请创建它。此目录将是您提示文件的位置。 - 在
.github/prompts目录中创建提示文件。提示文件名可以包含字母数字字符和空格,并应描述文件将包含的提示信息的目的。文件名必须以.prompt.md文件扩展名结尾,例如TESTPROMPT.prompt.md。 - 使用 Markdown 格式编写提示指令,然后保存文件。
使用设置页面创建提示文件
- 在您的 JetBrains IDE 中,点击 文件 菜单 (Windows),或菜单栏中应用程序的名称 (macOS),然后点击 设置。
- 在 工具 下,在 GitHub Copilot 下,点击 编辑设置。
- 在“设置类别”下,点击 自定义。
- 在“提示文件”下,点击 工作区,以在您的工作区中创建提示文件。
- 输入提示文件的名称,不包括
.prompt.md文件扩展名。提示文件名可以包含字母数字字符和空格,并应描述文件将包含的提示信息的目的。 - 点击 确定 保存提示文件名。
- 使用 Markdown 格式编写提示指令,然后保存文件。
使用提示文件
-
在聊天输入框中,键入
/,后跟提示文件的名称。例如,/TESTPROMPT。 -
可选地,附加其他文件,以提供更多上下文。
-
可选地,在聊天提示框中输入额外信息。
您是否需要这样做取决于您使用的提示内容。
-
提交聊天提示。
延伸阅读
本文版本介绍如何在 Xcode 中使用仓库自定义指令。点击上方选项卡可查看在其他环境中自定义指令的信息。
简介
仓库自定义指令允许您为 Copilot 提供仓库特定的指导和偏好。有关更多信息,请参阅关于自定义 GitHub Copilot 响应。
仓库自定义指令的先决条件
-
您必须有一个自定义指令文件(请参阅以下说明)。
-
您的 Xcode 中必须安装最新版本的 Copilot 扩展。
创建自定义指令
Xcode 支持存储在仓库中的单个 .github/copilot-instructions.md 自定义指令文件。
您可以通过 Copilot 设置页面在仓库中创建自定义指令文件。
指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
- 打开 GitHub Copilot for Xcode 应用程序。
- 在应用程序窗口顶部,在 设置 下,点击 高级。
- 在“自定义指令”右侧,点击 当前工作区 或 全局,选择自定义指令适用于当前工作区还是所有工作区。
正在使用的自定义指令
文件中的指令在您保存文件后即可供 Copilot 使用。指令会自动添加到您提交给 Copilot 的请求中。
自定义指令在聊天视图或行内聊天中不可见,但您可以通过查看聊天视图中响应的“引用”列表来验证它们是否正在被 Copilot 使用。如果自定义指令已添加到发送给模型的提示中,则 .github/copilot-instructions.md 文件将列为引用。您可以点击引用打开文件。
延伸阅读
注意
此功能目前处于公共预览阶段,可能会有所更改。
本文版本介绍如何在 Eclipse 中使用仓库自定义指令。点击上方选项卡可查看在其他环境中自定义指令的信息。
简介
仓库自定义指令允许您为 Copilot 提供仓库特定的指导和偏好。有关更多信息,请参阅关于自定义 GitHub Copilot 响应。
仓库自定义指令的先决条件
-
您必须有一个自定义指令文件(请参阅以下说明)。
-
您的 Eclipse 中必须安装最新版本的 Copilot 扩展。
创建自定义指令
Eclipse 支持两种类型的仓库自定义指令:工作区自定义指令和项目自定义指令。
要创建工作区自定义指令文件,您可以使用 Copilot 设置页面。要创建项目自定义指令文件,您可以手动在项目目录中创建文件。
指令之间的空白将被忽略,因此指令可以写成单个段落,每条指令在新的一行,或者为了易读性用空行分隔。
创建工作区自定义指令文件
- 要打开 Copilot Chat 面板,请点击 Eclipse 底部状态栏中的 Copilot 图标 () 在 Eclipse 底部状态栏中。
- 从菜单中,选择“编辑首选项”。
- 在左侧窗格中,展开 GitHub Copilot 并点击 自定义指令。
- 选择 启用工作区指令。
- 在“工作区”部分,“设置自定义指令以指导 Copilot 在此工作区中的代码建议”下方,以 Markdown 格式向文件中添加自然语言指令。
创建项目自定义指令文件
- 在项目目录的根目录中,创建一个名为
.github/copilot-instructions.md的文件。 - 使用 Markdown 格式添加您的自然语言自定义指令。
保存后,这些指令将应用于您在启用 Copilot 的情况下打开的 Eclipse 中的当前项目。
正在使用的自定义指令
文件中的指令在您保存文件后即可供 Copilot 使用。指令会自动添加到您提交给 Copilot 的请求中。
延伸阅读
- 对不同类型自定义指令的支持
- 自定义指令——精选示例集