git-commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit
Git 提交
Format
格式
<type>(<scope>): <description>| Type | When to use |
|---|---|
| A new capability, component, or behavior the project didn't have before (new skill, feature, command, config option). Not just any new file — purpose matters. |
| Correcting broken or incorrect behavior |
| Changes to documentation only (README, comments, markdown) |
| Restructuring existing code without changing behavior or adding features |
| Routine upkeep with no behavior change — bumping versions, updating lockfiles, adding |
| Adding or updating tests |
| Changes to CI/CD pipelines or workflow files |
| Undoing a previous commit |
Add after type/scope for breaking changes (e.g. ).
!feat!:<type>(<scope>): <description>| 类型 | 使用场景 |
|---|---|
| 项目此前不具备的新能力、组件或行为(如新技能、功能、命令、配置项)。并非任意新文件——用途才是关键。 |
| 修复已损坏或错误的行为 |
| 仅对文档进行修改(README、注释、Markdown文件) |
| 重构现有代码,不改变功能或添加新特性 |
| 日常维护工作,不改变功能——如版本升级、更新锁文件、添加 |
| 添加或更新测试用例 |
| 修改CI/CD流水线或工作流文件 |
| 撤销之前的提交 |
若为破坏性变更,可在类型/作用域后添加(例如)。
!feat!:Workflow
工作流程
-
Check if anything is staged:bash
git diff --cached --name-only- If files are listed → skip to step 3
- If nothing → continue to step 2
-
If nothing is staged, inspect all changes including untracked files:bash
git status --short # list all changed and untracked files git diff --name-only # list modified files with actual diff contentCross-check: only include a file if it actually has a diff or is genuinely untracked. Do not include files that appear inbut have no real changes ingit status.git diffIf there is nothing to commit, stop and tell the user.Otherwise, analyze all changes and group related files together. Unrelated changes go in separate commits. Stage only the first group:bashgit add <file1> <file2> -
Read the full staged diff, then analyze it to generate a commit message:bash
git diff --cached- Type: What kind of change?
- Scope: What module/area is affected? (required)
- Description: Present tense imperative, no period, ≤50 chars
-
STOP. Do not run any git commands yet.Output exactly this (with the actual generated message substituted in):
Proposed commit message:<generated message>What would you like to do?- Commit
1 - Edit message
2 - Cancel
3
Then stop and wait for the user to reply before doing anything. -
Act on the reply:
- → run
1git commit -m "<generated message>" - → ask for the new message, then repeat from step 4
2 - → abort, do nothing
3
If unstaged changes remain after committing, repeat from step 2.
-
检查是否有文件已暂存:bash
git diff --cached --name-only- 若列出文件 → 跳至步骤3
- 若无文件 → 继续步骤2
-
若没有文件暂存,检查所有变更(包括未跟踪文件):bash
git status --short # 列出所有已变更和未跟踪的文件 git diff --name-only # 列出有实际差异内容的已修改文件交叉验证:仅包含确实有差异或真正未跟踪的文件。不要包含在中显示但在git status中无实际变更的文件。git diff若无可提交内容,停止操作并告知用户。否则,分析所有变更并将相关文件分组。无关变更需分开提交。仅暂存第一组文件:bashgit add <file1> <file2> -
查看完整的暂存差异,然后分析并生成提交信息:bash
git diff --cached- 类型:变更属于哪种类型?
- 作用域:变更影响了哪个模块/区域?(必填)
- 描述:使用现在时祈使语气,无句号,长度≤50字符
-
停止操作,暂勿执行任何Git命令。输出以下内容(替换为实际生成的提交信息):
建议的提交信息:<生成的信息>您想要执行什么操作?- 提交
1 - 编辑信息
2 - 取消
3
然后停止操作,等待用户回复后再进行下一步。 -
根据回复执行操作:
- → 执行
1git commit -m "<生成的信息>" - → 请求用户提供新信息,然后回到步骤4
2 - → 中止操作,不执行任何动作
3
提交后若仍有未暂存的变更,回到步骤2重复流程。
Rules
规则
- ALWAYS include scope in parentheses
- ALWAYS use present tense imperative verb for the subject
- NEVER end subject with a period
- NEVER exceed 50 chars in the subject line
- NEVER use generic messages ("update code", "fix bug", "changes")
- NEVER use --no-verify
- NEVER use --force
- NEVER modify git config
- NEVER stage , credentials, or private keys
.env - Group related changes into a single focused commit; stage unrelated changes in separate commits
- If a pre-commit hook fails, stop and report the error — do not attempt to fix or bypass it
- If nothing is staged after , stop and tell the user
git add
- 必须在括号中包含作用域
- 必须使用现在时祈使动词作为主题
- 主题末尾绝不能加句号
- 主题长度绝不能超过50字符
- 绝不能使用通用表述(如"更新代码"、"修复bug"、"变更")
- 绝不能使用--no-verify参数
- 绝不能使用--force参数
- 绝不能修改Git配置
- 绝不能暂存文件、凭证或私钥
.env - 将相关变更分组为单个聚焦的提交;无关变更需分开提交
- 若预提交钩子失败,停止操作并报告错误——不要尝试修复或绕过
- 若后无文件被暂存,停止操作并告知用户
git add