git-commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Commit

Git 提交

Format

格式

<type>(<scope>): <description>
TypeWhen to use
feat
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.
fix
Correcting broken or incorrect behavior
docs
Changes to documentation only (README, comments, markdown)
refactor
Restructuring existing code without changing behavior or adding features
chore
Routine upkeep with no behavior change — bumping versions, updating lockfiles, adding
.gitignore
, renaming
test
Adding or updating tests
ci
Changes to CI/CD pipelines or workflow files
revert
Undoing a previous commit
Add
!
after type/scope for breaking changes (e.g.
feat!:
).
<type>(<scope>): <description>
类型使用场景
feat
项目此前不具备的新能力、组件或行为(如新技能、功能、命令、配置项)。并非任意新文件——用途才是关键。
fix
修复已损坏或错误的行为
docs
仅对文档进行修改(README、注释、Markdown文件)
refactor
重构现有代码,不改变功能或添加新特性
chore
日常维护工作,不改变功能——如版本升级、更新锁文件、添加
.gitignore
、重命名文件等
test
添加或更新测试用例
ci
修改CI/CD流水线或工作流文件
revert
撤销之前的提交
若为破坏性变更,可在类型/作用域后添加
!
(例如
feat!:
)。

Workflow

工作流程

  1. 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
  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 content
    Cross-check: only include a file if it actually has a diff or is genuinely untracked. Do not include files that appear in
    git status
    but have no real changes in
    git diff
    .
    If 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:
    bash
    git add <file1> <file2>
  3. 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
  4. 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?
    • 1
      Commit
    • 2
      Edit message
    • 3
      Cancel

    Then stop and wait for the user to reply before doing anything.
  5. Act on the reply:
    • 1
      → run
      git commit -m "<generated message>"
    • 2
      → ask for the new message, then repeat from step 4
    • 3
      → abort, do nothing
    If unstaged changes remain after committing, repeat from step 2.
  1. 检查是否有文件已暂存:
    bash
    git diff --cached --name-only
    • 若列出文件 → 跳至步骤3
    • 若无文件 → 继续步骤2
  2. 若没有文件暂存,检查所有变更(包括未跟踪文件):
    bash
    git status --short             # 列出所有已变更和未跟踪的文件
    git diff --name-only           # 列出有实际差异内容的已修改文件
    交叉验证:仅包含确实有差异或真正未跟踪的文件。不要包含在
    git status
    中显示但在
    git diff
    中无实际变更的文件。
    若无可提交内容,停止操作并告知用户。
    否则,分析所有变更并将相关文件分组。无关变更需分开提交。仅暂存第一组文件:
    bash
    git add <file1> <file2>
  3. 查看完整的暂存差异,然后分析并生成提交信息:
    bash
    git diff --cached
    • 类型:变更属于哪种类型?
    • 作用域:变更影响了哪个模块/区域?(必填)
    • 描述:使用现在时祈使语气,无句号,长度≤50字符
  4. 停止操作,暂勿执行任何Git命令。
    输出以下内容(替换为实际生成的提交信息):

    建议的提交信息:
    <生成的信息>
    您想要执行什么操作?
    • 1
      提交
    • 2
      编辑信息
    • 3
      取消

    然后停止操作,等待用户回复后再进行下一步。
  5. 根据回复执行操作:
    • 1
      → 执行
      git commit -m "<生成的信息>"
    • 2
      → 请求用户提供新信息,然后回到步骤4
    • 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
    .env
    , credentials, or private keys
  • 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
    git add
    , stop and tell the user
  • 必须在括号中包含作用域
  • 必须使用现在时祈使动词作为主题
  • 主题末尾绝不能加句号
  • 主题长度绝不能超过50字符
  • 绝不能使用通用表述(如"更新代码"、"修复bug"、"变更")
  • 绝不能使用--no-verify参数
  • 绝不能使用--force参数
  • 绝不能修改Git配置
  • 绝不能暂存
    .env
    文件、凭证或私钥
  • 将相关变更分组为单个聚焦的提交;无关变更需分开提交
  • 若预提交钩子失败,停止操作并报告错误——不要尝试修复或绕过
  • git add
    后无文件被暂存,停止操作并告知用户