git-commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Commit

Git提交

Rules

规则

  • Never add
    Co-Authored-By
    lines to commit messages
  • Never mention Claude, AI, agent, copilot, or any automated tooling
  • Commits must look like they were written by a human developer
  • 绝对不要在提交信息中添加
    Co-Authored-By
  • 绝对不要提及Claude、AI、agent、copilot或任何自动化工具
  • 提交信息必须看起来像是由人类开发者编写的

Format

格式

text
type(scope): subject

body (optional)
  • subject: lowercase, imperative mood, no period, max 72 chars
  • body: wrap at 72 chars, explain why not what, separated by blank line
text
type(scope): subject

body (optional)
  • subject(主题):小写、祈使语气、无句号,最多72个字符
  • body(正文):每行不超过72个字符,解释原因而非内容,与主题之间用空行分隔

Types

提交类型

TypeUse for
feat
New feature
fix
Bug fix
refactor
Code change that neither fixes nor adds
docs
Documentation only
style
Formatting, semicolons, no code change
test
Adding or updating tests
chore
Build, tooling, deps, no production code
perf
Performance improvement
ci
CI/CD configuration
类型适用场景
feat
新增功能
fix
修复Bug
refactor
既不修复Bug也不新增功能的代码变更
docs
仅修改文档
style
格式调整(如分号),无代码逻辑变更
test
添加或更新测试用例
chore
构建、工具、依赖更新,无生产代码变更
perf
性能优化
ci
CI/CD配置变更

Scope

作用域

Derive the scope from the primary area of change:
  • Module or package name (
    auth
    ,
    api
    ,
    db
    )
  • Feature area (
    login
    ,
    checkout
    ,
    search
    )
  • Layer (
    ui
    ,
    server
    ,
    cli
    )
Omit scope only when the change is truly project-wide.
从主要变更区域推导作用域:
  • 模块或包名称(
    auth
    api
    db
  • 功能区域(
    login
    checkout
    search
  • 层级(
    ui
    server
    cli
只有当变更真正涉及整个项目时,才可以省略作用域。

Workflow

工作流程

  1. Run
    git status
    and
    git diff --staged
    (or
    git diff
    if nothing staged)
  2. Identify the primary change type and scope
  3. Write the commit message
  4. Stage relevant files by name (avoid
    git add .
    or
    git add -A
    )
  5. Commit using a HEREDOC:
bash
git commit -m "$(cat <<'EOF'
type(scope): subject

optional body
EOF
)"
  1. 运行
    git status
    git diff --staged
    (如果没有暂存文件则运行
    git diff
  2. 确定主要变更类型和作用域
  3. 编写提交信息
  4. 按文件名暂存相关文件(避免使用
    git add .
    git add -A
  5. 使用HEREDOC进行提交:
bash
git commit -m "$(cat <<'EOF'
type(scope): subject

optional body
EOF
)"

Examples

示例

text
feat(auth): add password reset flow

Allow users to reset their password via email link.
Tokens expire after 30 minutes.
text
fix(api): handle null response from payment gateway
text
refactor(db): extract query builder into separate module
text
chore(deps): upgrade react to v19
text
feat(auth): add password reset flow

Allow users to reset their password via email link.
Tokens expire after 30 minutes.
text
fix(api): handle null response from payment gateway
text
refactor(db): extract query builder into separate module
text
chore(deps): upgrade react to v19