writing-commit-messages
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWriting 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
类型
| Type | When to use |
|---|---|
| New user-facing feature |
| Bug fix |
| Code restructuring without behavior change |
| Documentation changes |
| Adding or updating tests |
| Build, CI, tooling, deps |
| Performance improvement |
| Formatting, whitespace (not CSS) |
| CI/CD pipeline changes |
| Reverting a previous commit |
| 类型 | 使用场景 |
|---|---|
| 新增面向用户的功能 |
| 修复Bug |
| 代码重构,不改变功能行为 |
| 修改文档 |
| 添加或更新测试 |
| 构建、CI、工具、依赖相关操作 |
| 性能优化 |
| 格式调整、空白字符修改(非CSS样式) |
| CI/CD流水线变更 |
| 回滚之前的提交 |
Scope (Optional)
作用域(可选)
The area of the codebase affected:
feat(auth): add OAuth2 login flowfix(api): handle null response from payments endpointrefactor(db): extract query builder into module
受影响的代码库区域:
feat(auth): add OAuth2 login flowfix(api): handle null response from payments endpointrefactor(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.4Bad:
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
asdfWhen 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 instead)
git stash - Commit early and often on feature branches, squash before merge if needed
- 每个提交应代表一个逻辑变更
- 不要在同一个提交中混合重构和功能开发
- 不要提交未完成的代码(改用)
git stash - 在功能分支上尽早且频繁提交,合并前如有需要可压缩提交
Breaking Changes
破坏性变更
If the commit introduces a breaking change:
- Add after the type:
!feat(api)!: change auth token format - Add in the footer with migration instructions
BREAKING CHANGE:
如果提交引入破坏性变更:
- 在类型后添加:
!feat(api)!: change auth token format - 在页脚中添加并附上迁移说明
BREAKING CHANGE: