commit-work

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Commit work

提交工作

Goal

目标

Make commits that are easy to review and safe to ship:
  • only intended changes are included
  • commits are logically scoped (split when needed)
  • commit messages describe what changed and why
创建易于审核且可安全发布的提交记录:
  • 仅包含预期的变更
  • 提交记录具备合理的范围(必要时拆分)
  • 提交信息说明变更内容及原因

Inputs to ask for (if missing)

需询问的输入信息(若缺失)

  • Single commit or multiple commits? Default to multiple small commits when there are unrelated changes.
  • Any extra rules: max subject length, required scopes.
  • 单次提交还是多次提交?当存在不相关变更时,默认拆分为多个小型提交。
  • 额外规则:主题最大长度、必填范围等。

Workflow

工作流程

  1. Inspect the working tree
    • git status
      and
      git diff
      (unstaged)
    • If many changes:
      git diff --stat
  2. Decide commit boundaries (split if needed)
    • Split by: feature vs refactor, backend vs frontend, formatting vs logic, tests vs prod code, dependency bumps vs behavior changes
    • If you cannot describe the commit cleanly in one sentence, it's too big — split further
  3. Stage only what belongs in the next commit
    • Use
      git add -p
      for mixed changes in one file
    • To unstage:
      git restore --staged -p
      or
      git restore --staged <path>
  4. Review what will be committed
    • git diff --cached
    • Verify: no secrets/tokens, no debug logging, no unrelated formatting churn
  5. Describe the staged change in 1-2 sentences before writing the message
    • "What changed?" + "Why?"
    • If you cannot describe it cleanly, the commit is probably too big or mixed — go back to step 2
  6. Write the commit message (see format below)
    • Prefer
      git commit -v
      for multi-line messages
  7. Verify — run the repo's fastest relevant check (lint, unit tests, or build)
  8. Repeat for the next commit until the working tree is clean
  1. 检查工作区
    • 执行
      git status
      git diff
      (查看未暂存变更)
    • 若变更较多:执行
      git diff --stat
  2. 确定提交边界(必要时拆分)
    • 拆分依据:功能新增 vs 代码重构、后端 vs 前端、格式调整 vs 逻辑修改、测试代码 vs 生产代码、依赖更新 vs 行为变更
    • 若无法用一句话清晰描述提交内容,说明提交范围过大——需进一步拆分
  3. 暂存仅属于下一次提交的内容
    • 若单个文件存在混合变更,使用
      git add -p
    • 取消暂存:执行
      git restore --staged -p
      git restore --staged <path>
  4. 审核即将提交的内容
    • 执行
      git diff --cached
    • 验证:无密钥/令牌、无调试日志、无无关格式变更
  5. 撰写提交信息前,用1-2句话描述暂存的变更
    • 包含“变更了什么?” + “为什么变更?”
    • 若无法清晰描述,说明提交可能范围过大或内容混杂——回到步骤2
  6. 撰写提交信息(格式见下文)
    • 多行信息优先使用
      git commit -v
  7. 验证——执行仓库中最相关的快速检查(代码检查、单元测试或构建)
  8. 重复上述步骤,直到工作区无待处理变更

Organization Rules

整理规则

  • Changes with their tests go in the same commit
  • If 2 unrelated changes are in one file, use patch staging to organize commits
  • Documentation files (README.md, Schemas.yaml, etc.) go in separate commit
  • Translation files go in separate commit
  • Separate dependency installation from usage (two commits)
  • One commit = one responsibility
  • 变更代码与其对应的测试代码需放在同一个提交中
  • 若单个文件包含2项不相关变更,使用补丁暂存功能整理提交
  • 文档文件(README.md、Schemas.yaml等)单独提交
  • 翻译文件单独提交
  • 依赖安装与依赖使用拆分(分为两个提交)
  • 一个提交对应一项职责

Commit Format

提交格式

Format:
type(context): description
格式:
type(context): description

Types

类型

  • feat: new feature
  • fix: bug fix
  • docs: documentation changes
  • style: formatting, no code change
  • refactor: code change without new feature or fix
  • perf: performance improvement
  • test: adding or fixing tests
  • chore: build process or auxiliary tools
  • feat: 新增功能
  • fix: 修复bug
  • docs: 文档变更
  • style: 格式调整,无代码逻辑变更
  • refactor: 代码重构,无新增功能或bug修复
  • perf: 性能优化
  • test: 添加或修复测试
  • chore: 构建流程或辅助工具变更

Rules

规则

  • Context in
    kebab-case
    (e.g.,
    user-signup
    )
  • Optional component after context with
    /
    (e.g.,
    api/LoginService
    )
  • Imperative verb: "add" not "added" or "adds"
  • No capital letter at start
  • No period at end
  • Max 100 characters
  • Body (optional): what changed and why, not implementation diary
  • Footer:
    BREAKING CHANGE:
    if applicable
  • 上下文使用
    kebab-case
    格式(如:
    user-signup
  • 可在上下文后添加组件,用
    /
    分隔(如:
    api/LoginService
  • 使用祈使动词:用“add”而非“added”或“adds”
  • 开头无需大写
  • 结尾无需加句号
  • 最大长度100字符
  • 正文(可选):说明变更内容及原因,而非实现过程
  • 页脚:若涉及破坏性变更,需添加
    BREAKING CHANGE:

Deliverable

交付物

  • The final commit message(s)
  • A short summary per commit (what/why)
  • The commands used to stage/review (at minimum:
    git diff --cached
    , plus any tests run)
  • 最终的提交信息
  • 每个提交的简短摘要(内容/原因)
  • 用于暂存/审核的命令(至少包含:
    git diff --cached
    ,以及执行的测试命令)

Important

注意事项

  • Keep messages concise and direct
  • 提交信息需简洁直接