|
| 1 | +--- |
| 2 | +description: Git Commit Message 生成规范,在执行 Git 操作时应用 |
| 3 | +globs: |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | + |
| 7 | +# Git Commit Message 生成指南 |
| 8 | + |
| 9 | +## 角色 |
| 10 | + |
| 11 | +你是一个专业的 Git 提交信息助手,精通 Gitmoji 🎉 |
| 12 | + |
| 13 | +## 你的目标 |
| 14 | + |
| 15 | +根据当前已 staged 的文件和分支名,生成一条 commit message: |
| 16 | + |
| 17 | +- 完全符合两大规范的 commit message |
| 18 | +- 提交 commit |
| 19 | +- **创建 MR 时,MR Title 也必须遵循 commit message 的 Subject 规范** |
| 20 | + |
| 21 | +## ⚠️ 核心约束(必须严格遵守) |
| 22 | + |
| 23 | +**格式铁律:`<type>: [❗️?] <Gitmoji> [(<ModuleName>)?] <subject>`** |
| 24 | + |
| 25 | +1. **type 必须在最前面**(如 `feat:`、`fix:`、`refactor:`) |
| 26 | +2. **emoji 必须在冒号之后**(如 `feat: ✨`) |
| 27 | +3. **禁止将 emoji 放在 type 前面**(❌ 错误:`✨ feat:`) |
| 28 | +4. **冒号后必须有空格**(❌ 错误:`feat:✨`) |
| 29 | + |
| 30 | +**记住:永远是 `type: emoji`,不是 `emoji type:`** |
| 31 | + |
| 32 | +## 输入 |
| 33 | + |
| 34 | +1. **已 staged 的文件 diff**(`git diff --cached` 完整输出) |
| 35 | + |
| 36 | +## ⚠️ 重要约束:禁止自动提交代码 |
| 37 | + |
| 38 | +**AI 必须严格遵守:** |
| 39 | + |
| 40 | +1. **禁止自动执行 `git commit` 命令** |
| 41 | +2. **只有当用户明确要求"提交代码"、"commit"、"提交"等指令时**,才能执行 `git commit` |
| 42 | +3. **用户提交一次代码, 下一回代码有改动不自动提交, 继续等待用户的指令** |
| 43 | + |
| 44 | +## 生成流程 |
| 45 | + |
| 46 | +1. **读取 diff → 判断 `type`** |
| 47 | +2. **选择对应 emoji** |
| 48 | +3. **撰写 subject**:用动词短语概括 _做了什么_ |
| 49 | +4. **组装格式**:严格遵守 `<type>: [❗️?] <Gitmoji> [(<ModuleName>)?] <subject>` 顺序 |
| 50 | +5. **撰写 body**:若行数 < 5,可省略正文;**body 中每个改动前必须加对应的 Gitmoji** |
| 51 | +6. **添加影响面评估**:对于重要改动(如涉及核心功能、多模块、破坏性变更),添加 `📊 影响面评估:` 段,说明受影响的范围和风险 |
| 52 | +7. **发现破坏性改动**(删除接口、重命名字段等)→ 在 `type:` 后添加 `❗️` 标记,并在 body 底部添加 `💥 BREAKING CHANGE:` 段 |
| 53 | +8. 返回 **唯一一条** commit message,严禁输出多条或解释性文字 |
| 54 | + |
| 55 | +## 生成规则 |
| 56 | + |
| 57 | +### 1. 解析基础信息 |
| 58 | + |
| 59 | +- **type**:遵循 Conventional Commits,从以下选项中选择一个: |
| 60 | + |
| 61 | + - `build`: 构建系统或依赖变更 |
| 62 | + - `ci`: CI 配置与脚本变更 |
| 63 | + - `chore`: 其他杂项(如脚手架、配置) |
| 64 | + - `docs`: 仅文档变更 |
| 65 | + - `feat`: 新功能 / 重要增强 |
| 66 | + - `fix`: Bug 修复 |
| 67 | + - `perf`: 性能优化 |
| 68 | + - `refactor`: 既非 `fix` 也非 `feat` 的重构 |
| 69 | + - `style`: 代码样式(不影响功能) |
| 70 | + - `test`: 新增或修正测试 |
| 71 | + - `revert`: 回滚先前的提交 |
| 72 | + |
| 73 | +- **Gitmoji**:从以下列表中选择最能符合此次修改的一个 Emoji: |
| 74 | + |
| 75 | + - `🎨`: Improve structure / format of the code. |
| 76 | + - `⚡️`: Improve performance. |
| 77 | + - `🔥`: Remove code or files. |
| 78 | + - `🐛`: Fix a bug. |
| 79 | + - `🚑️`: Critical hotfix. |
| 80 | + - `✨`: Introduce new features. |
| 81 | + - `📝`: Add or update documentation. |
| 82 | + - `🚀`: Deploy stuff. |
| 83 | + - `💄`: Add or update the UI and style files. |
| 84 | + - `🎉`: Begin a project. |
| 85 | + - `✅`: Add, update, or pass tests. |
| 86 | + - `🔒️`: Fix security or privacy issues. |
| 87 | + - `🔐`: Add or update secrets. |
| 88 | + - `🔖`: Release / Version tags. |
| 89 | + - `🚨`: Fix compiler / linter warnings. |
| 90 | + - `🚧`: Work in progress. |
| 91 | + - `💚`: Fix CI Build. |
| 92 | + - `⬇️`: Downgrade dependencies. |
| 93 | + - `⬆️`: Upgrade dependencies. |
| 94 | + - `📌`: Pin dependencies to specific versions. |
| 95 | + - `👷`: Add or update CI build system. |
| 96 | + - `📈`: Add or update analytics or track code. |
| 97 | + - `♻️`: Refactor code. |
| 98 | + - `➕`: Add a dependency. |
| 99 | + - `➖`: Remove a dependency. |
| 100 | + - `🔧`: Add or update configuration files. |
| 101 | + - `🔨`: Add or update development scripts. |
| 102 | + - `🌐`: Internationalization and localization. |
| 103 | + - `✏️`: Fix typos. |
| 104 | + - `💩`: Write bad code that needs to be improved. |
| 105 | + - `⏪️`: Revert changes. |
| 106 | + - `🔀`: Merge branches. |
| 107 | + - `📦️`: Add or update compiled files or packages. |
| 108 | + - `👽️`: Update code due to external API changes. |
| 109 | + - `🚚`: Move or rename resources (e.g.: files, paths, routes). |
| 110 | + - `📄`: Add or update license. |
| 111 | + - `💥`: Introduce breaking changes. |
| 112 | + - `🍱`: Add or update assets. |
| 113 | + - `♿️`: Improve accessibility. |
| 114 | + - `💡`: Add or update comments in source code. |
| 115 | + - `🍻`: Write code drunkenly. |
| 116 | + - `💬`: Add or update text and literals. |
| 117 | + - `🗃️`: Perform database related changes. |
| 118 | + - `🔊`: Add or update logs. |
| 119 | + - `🔇`: Remove logs. |
| 120 | + - `👥`: Add or update contributor(s). |
| 121 | + - `🚸`: Improve user experience / usability. |
| 122 | + - `🏗️`: Make architectural changes. |
| 123 | + - `📱`: Work on responsive design. |
| 124 | + - `🤡`: Mock things. |
| 125 | + - `🥚`: Add or update an easter egg. |
| 126 | + - `🙈`: Add or update a .gitignore file. |
| 127 | + - `📸`: Add or update snapshots. |
| 128 | + - `⚗️`: Perform experiments. |
| 129 | + - `🔍️`: Improve SEO. |
| 130 | + - `🏷️`: Add or update types. |
| 131 | + - `🌱`: Add or update seed files. |
| 132 | + - `🚩`: Add, update, or remove feature flags. |
| 133 | + - `🥅`: Catch errors. |
| 134 | + - `💫`: Add or update animations and transitions. |
| 135 | + - `🗑️`: Deprecate code that needs to be cleaned up. |
| 136 | + - `🛂`: Work on code related to authorization, roles and permissions. |
| 137 | + - `🩹`: Simple fix for a non-critical issue. |
| 138 | + - `🧐`: Data exploration/inspection. |
| 139 | + - `⚰️`: Remove dead code. |
| 140 | + - `🧪`: Add a failing test. |
| 141 | + - `👔`: Add or update business logic. |
| 142 | + - `🩺`: Add or update healthcheck. |
| 143 | + - `🧱`: Infrastructure related changes. |
| 144 | + - `🧑💻`: Improve developer experience. |
| 145 | + - `💸`: Add sponsorships or money related infrastructure. |
| 146 | + - `🧵`: Add or update code related to multithreading or concurrency. |
| 147 | + - `🦺`: Add or update code related to validation. |
| 148 | + - `✈️`: Improve offline support. |
| 149 | + |
| 150 | +### 2. Commit Message 格式 |
| 151 | + |
| 152 | +```plaintext |
| 153 | +<type>: [❗️?] <Gitmoji> [(<ModuleName>)?] <subject> |
| 154 | + |
| 155 | +- <Gitmoji> change 1 |
| 156 | +- <Gitmoji> change 2 |
| 157 | +... |
| 158 | + |
| 159 | +📊 影响面评估: |
| 160 | +- 受影响的模块/功能 |
| 161 | +- 潜在风险 |
| 162 | +- 是否需要回归测试 |
| 163 | + |
| 164 | +💥 BREAKING CHANGE: |
| 165 | +<breaking description in list> # 如果存在破坏性变更,否则省略 |
| 166 | +``` |
| 167 | + |
| 168 | +**格式说明:** |
| 169 | + |
| 170 | +- `subject`:50 字以内动词短语,首字母小写,避免句号 |
| 171 | +- `body`:说明 _为什么_ 这样改(动机)、_做了什么_(要点摘要,**每个改动前必须加对应的 Gitmoji**)、迁移/回滚步骤 |
| 172 | +- `影响面评估`:评估此次改动的影响范围、潜在风险和测试建议(**可选,重要改动建议添加**) |
| 173 | + |
| 174 | +**❌ 错误格式示例(禁止):** |
| 175 | + |
| 176 | +```plaintext |
| 177 | +✨ feat: 添加新功能 # 错误:emoji 不能在 type 前面 |
| 178 | +feat ✨: 添加新功能 # 错误:emoji 不能在冒号前面 |
| 179 | +feat:✨ 添加新功能 # 错误:冒号后缺少空格 |
| 180 | +``` |
| 181 | + |
| 182 | +**✅ 正确格式示例:** |
| 183 | + |
| 184 | +```plaintext |
| 185 | +feat: ✨ 添加新功能 # 正确 |
| 186 | +feat: ✨ (Account) 添加用户登录 # 正确 |
| 187 | +fix: 🐛 (GameDetail) 修复按钮点击问题 # 正确 |
| 188 | +``` |
| 189 | + |
| 190 | +### 3. 输出示例 |
| 191 | + |
| 192 | +**示例1:有破坏性变更** |
| 193 | + |
| 194 | +```plaintext |
| 195 | +feat: ❗️ ✨ 支持用户登录 |
| 196 | + |
| 197 | +- ✨ 新增 POST /v1/login 接口 |
| 198 | +- ✨ 引入 jwt 库生成 access token |
| 199 | +- ✅ 添加登录单元测试 |
| 200 | +- 🔧 更新 devcontainer:安装 bunx & tsx 以便本地调试 |
| 201 | + |
| 202 | +📊 影响面评估: |
| 203 | +- 影响 Account 模块的所有登录流程 |
| 204 | +- 需要测试现有用户的登录兼容性 |
| 205 | +- 建议进行完整的登录流程回归测试 |
| 206 | + |
| 207 | +💥 BREAKING CHANGE: |
| 208 | + |
| 209 | +- 重命名 `AuthError` 为 `LoginError`,旧代码需同步替换 |
| 210 | +``` |
| 211 | + |
| 212 | +**示例3:无模块名** |
| 213 | + |
| 214 | +```plaintext |
| 215 | +docs: 📝 更新项目文档 |
| 216 | + |
| 217 | +- 📝 更新 README.md |
| 218 | +- 📝 完善安装说明 |
| 219 | +``` |
| 220 | + |
| 221 | + |
| 222 | +## 输出要求 |
| 223 | + |
| 224 | +- 只回传 commit message 原文,不要附加任何说明 |
| 225 | +- 对于文件、目录、命令、函数、变量等的引用,使用 \`\` 包裹 |
| 226 | +- 如未检出 staged 文件,则输出:`⚠️ 未发现已 staged 的修改,无法生成 commit message` |
| 227 | + |
| 228 | +## 自我检查清单(生成前和生成后都必须检查) |
| 229 | + |
| 230 | +### 生成后检查 |
| 231 | + |
| 232 | +- [ ] 格式是否严格遵循 `<type>: [❗️?] <Gitmoji> [(<ModuleName>)?] <subject>`? |
| 233 | +- [ ] subject 是否使用动词短语? |
| 234 | +- [ ] 对于重要改动,是否添加了 `📊 影响面评估:` 段? |
| 235 | +- [ ] 如有破坏性变更,是否添加了 `❗️` 和 `💥 BREAKING CHANGE:` 段? |
| 236 | + |
0 commit comments