writing-commit-messages

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Writing Commit Messages

编写提交信息

Write commit messages that are useful for humans and machines.
编写对人类和机器都有用的提交信息。

Format

格式

<type>(<optional scope>): <subject>

<optional body>

<optional footer>
<type>(<可选作用域>): <主题>

<可选正文>

<可选页脚>

Subject Line Rules

主题行规则

  • 50 characters or less for the subject
  • Use imperative mood: "add feature" not "added feature" or "adding feature"
  • Don't capitalize the first letter after the type prefix
  • No period at the end
  • 50个字符或更少的主题长度
  • 使用祈使语气:例如用"add feature"而非"added feature"或"adding feature"
  • 类型前缀后的第一个单词不要大写
  • 结尾不要加句号

Types

类型

TypeWhen to use
feat
New user-facing feature
fix
Bug fix
refactor
Code restructuring without behavior change
docs
Documentation changes
test
Adding or updating tests
chore
Build, CI, tooling, deps
perf
Performance improvement
style
Formatting, whitespace (not CSS)
ci
CI/CD pipeline changes
revert
Reverting a previous commit
类型使用场景
feat
新增面向用户的功能
fix
修复Bug
refactor
代码重构,不改变功能行为
docs
修改文档
test
添加或更新测试
chore
构建、CI、工具、依赖相关操作
perf
性能优化
style
格式调整、空白字符修改(非CSS样式)
ci
CI/CD流水线变更
revert
回滚之前的提交

Scope (Optional)

作用域(可选)

The area of the codebase affected:
  • feat(auth): add OAuth2 login flow
  • fix(api): handle null response from payments endpoint
  • refactor(db): extract query builder into module
受影响的代码库区域:
  • feat(auth): add OAuth2 login flow
  • fix(api): handle null response from payments endpoint
  • refactor(db): extract query builder into module

Body (When Needed)

正文(必要时使用)

Explain why, not what (the diff shows what):
fix(checkout): prevent duplicate order submissions

The submit button was not disabled after the first click,
allowing users to create multiple orders. This caused
duplicate charges in Stripe.
解释原因,而非内容(代码差异会展示内容):
fix(checkout): prevent duplicate order submissions

The submit button was not disabled after the first click,
allowing users to create multiple orders. This caused
duplicate charges in Stripe.

Footer (When Needed)

页脚(必要时使用)

BREAKING CHANGE: rename `getUserById` to `findUser`

Closes #456
Co-authored-by: Name <email>
BREAKING CHANGE: rename `getUserById` to `findUser`

Closes #456
Co-authored-by: Name <email>

Examples

示例

Good:
feat(dashboard): add real-time notification bell
fix: resolve race condition in WebSocket reconnect
refactor(api): consolidate error handling middleware
test: add integration tests for payment webhook
chore: upgrade TypeScript to 5.4
Bad:
fixed stuff
WIP
update
changes
asdf
良好示例:
feat(dashboard): add real-time notification bell
fix: resolve race condition in WebSocket reconnect
refactor(api): consolidate error handling middleware
test: add integration tests for payment webhook
chore: upgrade TypeScript to 5.4
不良示例:
fixed stuff
WIP
update
changes
asdf

When to Commit

提交时机

  • Each commit should represent one logical change
  • Don't mix refactoring with feature work in the same commit
  • Don't commit half-working code (use
    git stash
    instead)
  • Commit early and often on feature branches, squash before merge if needed
  • 每个提交应代表一个逻辑变更
  • 不要在同一个提交中混合重构和功能开发
  • 不要提交未完成的代码(改用
    git stash
    )
  • 在功能分支上尽早且频繁提交,合并前如有需要可压缩提交

Breaking Changes

破坏性变更

If the commit introduces a breaking change:
  1. Add
    !
    after the type:
    feat(api)!: change auth token format
  2. Add
    BREAKING CHANGE:
    in the footer with migration instructions
如果提交引入破坏性变更:
  1. 在类型后添加
    !
    :
    feat(api)!: change auth token format
  2. 在页脚中添加
    BREAKING CHANGE:
    并附上迁移说明