GitHub Copilot 在 VSCode 和 JetBrains Rider 中生成 Conventional Commit 消息
Source: Dev.to
请提供您希望翻译的正文内容,我将按照要求保留源链接、格式和代码块,仅翻译文本部分。
大多数提交信息毫无用处
fix stuffupdate codechanges
它们在当下有效,但六个月后(实际上是一月后)就失效了。
提交信息 不仅 为今天或某个特殊场景而写。它们是为:
- 未来的自己
- 你的团队成员
- 自动化流水线
- 变更日志生成器
- 语义化版本控制
编写结构化的提交信息需要自律。压力下这种自律会消失,即使没有压力我们也常常懒惰。
这就是 GitHub Copilot 变得有趣的地方
你可以不仅将 Copilot 用于代码,还可以将其作为 提交质量的护栏。通过正确的指令,它可以自动生成严格的 Conventional Commit 信息,直接在以下环境中使用:
- VS Code
- JetBrains Rider
为什么传统提交仍然重要
传统提交并不是关于风格;它们关注的是 结构。
格式很简单:
type(scope): description
示例
feat(auth): add JWT token validation
fix(api): handle null response in user endpoint
refactor(ui): simplify navbar component
可读的 Git 历史
不佳的历史
update stuff
fix bug
changes
良好的历史
fix(auth): prevent null pointer on login
feat(api): add user filtering by role
ci(github-actions): add build cache
第二段历史是自解释的。
使用 GitHub Copilot 在 VS Code 中生成提交信息
Copilot 可以直接从 Source Control 面板生成提交信息。默认生成的内容比较通用;自定义指令可以让它更严格。
将以下内容添加到你的 settings.json:
"github.copilot.chat.commitMessageGeneration.instructions": [
{ "text": "Follow Conventional Commits: type(scope): description." },
{ "text": "Use lowercase type and scope." },
{ "text": "Use imperative mood: 'add', 'fix', 'update', not past tense." },
{ "text": "Keep subject under 50 characters. No period." },
{ "text": "Describe the intent clearly. Avoid vague messages like 'update code'." },
{ "text": "Use only these types: feat, fix, docs, style, refactor, perf, test, chore, ci." },
{ "text": "Include a scope when the change targets a specific area." },
{ "text": "Ensure each commit represents one logical change." },
{ "text": "Add a body when needed, separated by a blank line." },
{ "text": "Use bullet points (*) in the body for multiple changes." },
{ "text": "Explain why the change was made, not only what changed." },
{ "text": "Add BREAKING CHANGE: in the footer when applicable." }
]
之前(通用)
update login logic
之后(使用 Copilot)
fix(auth): prevent null pointer on login
* add null check for user object
* improve error handling for invalid credentials
这些规则使 Copilot 的输出保持一致。
使用 GitHub Copilot 在 JetBrains Rider 中编写提交信息
在 Rider 中,Copilot 集成到 Commit 工具窗口。通过严格的指令,你可以强制完全遵守规范。
指令模板
Follow the Conventional Commits specification strictly.
():
All sections except the first line are optional.
Use only these types: feat, fix, docs, style, refactor, perf, test, chore, ci.
Max 50 characters. Imperative mood. No period.
Each commit must represent one logical change.
Use BREAKING CHANGE: footer when applicable.
示例输出
feat(auth): add refresh token support
* implement refresh token endpoint
* update token validation logic
* improve session security
破坏性变更示例
refactor(api): rename user endpoint
BREAKING CHANGE: /users endpoint is now /v2/users
通过 Settings → Tools → GitHub Copilot → Git Commit Instructions → Global 进行配置。
注意: Rider 允许更冗长的强制执行,而 VS Code 更倾向于紧凑的规则列表。两种方式都可使用。
让 Copilot 更严格(而非创造性)
Copilot 会预测文本;约束可以降低变异性。
关键原则
- 编写硬性规则,而不是建议。
- 限制允许的类型。
- 强制原子提交。
- 要求使用正确的 BREAKING‑CHANGE 脚注。
- 在提交前审查输出。
Copilot 并不是要取代判断,它只会消除重复的格式化工作。当配置得当时,编写一个符合规范的 Conventional Commit 要比写一个糟糕的提交更容易。
👀 在 VS Code 中查看 GitHub Copilot 配额
如果您使用 GitHub Copilot 并且曾经想了解:
- 您使用的是哪种计划?
- 是否有使用限制?
- 您剩余的高级使用额度是多少?
您可以直接在 VS Code 中查看配额信息(见下图)。

借助 GitHub Copilot,让您的提交历史保持整洁、可读且面向未来。
Copilot Insights
- 剩余配额
- 重置时间
我构建了一个小型 VS Code 扩展,名为 Copilot Insights。
它直接在 VS Code 中显示 Copilot 计划和配额状态。
- 无使用分析。
- 无生产力评分。
- 仅提供清晰度。
👉 VS Code 市场:
https://marketplace.visualstudio.com/items?itemName=emanuelebartolesi.vscode-copilot-insights