GitLens 提交消息自定义指令
在 VS Code 的 settings.json
文件中添加 gitlens.ai.generateCommitMessage.customInstructions
配置项:
json
{
"gitlens.ai.generateCommitMessage.customInstructions": "Generate commit messages in the format of \"[<Type>] (<Scope>): <Brief Description>\" where Type and Scope are in English, but Description is in Chinese.\n\nTypes: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert\nScope: optional component/module name (e.g. api, ui, auth)\n\nRequirements:\n1. First line should not exceed 50 characters\n2. Brief Description should be written in Chinese, clearly explaining the change\n3. Add a blank line after the title\n4. Body paragraph in Chinese explaining:\n - Why this change was made (problem solved)\n - What was changed specifically\n - Any impacts or side effects\n\nReference issues at the end with \"关联: #123\" or \"修复: #456\"\n\nExample:\n[feat] (user): 添加用户头像上传功能\n\n实现了个人资料页面的头像上传与裁剪功能。\n优化了图片压缩算法,确保上传文件不超过2MB。\n添加了文件格式验证,仅允许jpg/png格式。\n\n关联: #123"
}
提交消息格式说明
md
Generate commit messages in the format of "[<Type>] (<Scope>): <Brief Description>" where Type and Scope are in English, but Description is in Chinese.
Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
Scope: optional component/module name (e.g. api, ui, auth)
Requirements:
1. First line should not exceed 50 characters
2. Brief Description should be written in Chinese, clearly explaining the change
3. Add a blank line after the title
4. Body paragraph in Chinese explaining:
- Why this change was made (problem solved)
- What was changed specifically
- Any impacts or side effects
Reference issues at the end with "关联: #123" or "修复: #456"
Example:
[feat] (user): 添加用户头像上传功能
实现了个人资料页面的头像上传与裁剪功能。
优化了图片压缩算法,确保上传文件不超过2MB。
添加了文件格式验证,仅允许jpg/png格式。
关联: #123
标题行格式
md
[<Type>] (<Scope>): <Brief Description>
Type: 英文,表示提交类型
feat
: 新功能fix
: 修复bugdocs
: 文档变更style
: 代码格式调整refactor
: 代码重构perf
: 性能优化test
: 测试相关build
: 构建系统相关ci
: 持续集成相关chore
: 其他变更revert
: 撤销提交
Scope: 可选,英文,表示修改范围,如组件/模块名称
Brief Description: 中文简短描述,总长度(包括Type和Scope)不超过50字符
正文格式
正文使用中文撰写,应包含:
- 为什么进行此次修改(解决了什么问题)
- 具体做了哪些修改
- 可能产生的影响或副作用
引用关联内容
在消息末尾添加关联的任务或问题编号:
- 关联: #123
- 修复: #456
示例
md
[feat] (user): 添加用户头像上传功能
实现了个人资料页面的头像上传与裁剪功能。
优化了图片压缩算法,确保上传文件不超过2MB。
添加了文件格式验证,仅允许jpg/png格式。
关联: #123
使用方法
- 完成代码修改后,在 GitLens 面板中选择"Generate Commit Message with GitLens"
- AI 将根据自定义模板生成符合规范的提交消息
- 根据需要微调生成的消息内容
- 提交代码