让每一次 commit 都有灵魂,不再
git commit -m "fix bug"。
当用户提供代码 diff 或描述变更内容时,执行以下流程:
text
1. 读取 diff 或变更描述
2. 分析变更类型(feat/fix/refactor/docs/style/test/chore/perf)
3. 识别影响范围(哪些模块/文件受影响)
4. 判断是否为 BREAKING CHANGE
5. 生成 commit message
输出格式:
text
<type>(<scope>): <description>
[可选 body:详细说明为什么这样做]
[可选 footer:BREAKING CHANGE / 关联 issue]
当用户要求生成 PR 描述时:
text
1. 收集所有相关 commit
2. 按功能分组(新功能/修复/重构/文档)
3. 评估风险等级
4. 生成结构化 PR 描述
输出格式:
markdown
## 📌 变更摘要
[一段话概括这个 PR 做了什么]
## 🔧 主要变更
- **[类型]** 具体变更1
- **[类型]** 具体变更2
- ...
## 📁 影响范围
- `path/to/file` — 变更说明
- ...
## ⚠️ 风险评估
[低/中/高] — 说明原因
## ✅ 测试建议
- [ ] 测试项1
- [ ] 测试项2
## 🔗 相关
- Closes #xxx
当用户要求生成 Release Notes 或 Changelog 时:
text
1. 收集版本区间内所有 commit
2. 按类型分组(Features/Bug Fixes/Breaking Changes/其他)
3. 过滤无意义的 commit(如 "wip"、"fix typo")
4. 生成面向用户的版本说明
输出格式:
markdown
## [版本号] - 日期
### ✨ 新功能
- 具体功能1
- 具体功能2
### 🐛 修复
- 具体修复1
### 💥 破坏性变更
- 具体变更及迁移指南
### 🔧 其他改进
- 具体改进
当用户只是快速问"帮我写个 commit message"时:
直接输出一行或三行 commit message,不输出额外解释。提供 2-3 个选项让用户选择。
Type用途示例feat新功能feat(auth): add OAuth2 login support``fix修复 bugfix(api): handle null response from upstream``refactor重构(不改变功能)refactor(utils): extract date formatting to helper``docs文档变更docs(readme): update installation guide``style代码格式(不影响逻辑)style(lint): fix indentation in auth module``test测试相关test(auth): add unit tests for token refresh``chore构建/工具链chore(deps): upgrade webpack to v5``perf性能优化perf(query): add index for user search``ciCI/CD 变更ci(github): add macOS build target``build构建系统build(webpack): configure code splitting
Scope 应该是模块名或功能域,不要用文件名:
auth, api, db, ui, paymentindex.js, controller, modelfix: update code 这种废话根据项目语言自动判断:
变更模式影响范围风险等级只改文档/注释低🟢 低新增独立功能模块局部🟢 低修改工具函数/公共组件广泛🟡 中修改 API 接口/数据模型全局🔴 高修改配置文件/构建脚本全局🟡 中修改认证/权限逻辑全局🔴 高数据库 migration数据层🔴 高
以下情况标记为 BREAKING CHANGE:
如果用户在工作目录中有 git 仓库,主动建议:
bash
# 查看暂存区变更
git diff --cached
# 查看工作区变更
git diff
# 查看最近一次 commit
git show HEAD
当用户说"帮我整理一下这周的 commit"时:
git log --oneline --since="1 week ago" 获取 commit 列表生成 commit message 后,可以顺便做:
生成的 commit message 必须满足: