conventional-git
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseConventional Commits & Branch Naming
Conventional Commits 分支命名与提交消息规范
Follow Conventional Commits v1.0.0 for both branch names and commit messages — consistent naming lets tools auto-generate changelogs, enforce SemVer bumps, and filter history by concern.
分支名称和提交消息均需遵循Conventional Commits v1.0.0规范——统一的命名规则可让工具自动生成变更日志、强制执行SemVer版本号升级,并按关注点过滤历史记录。
Branch Naming
分支命名规则
Format: — lowercase, hyphens only, no special chars except .
<type>/[issue-]<description>/feat/user-authentication
feat/42-user-authentication
fix/login-race-condition
fix/87-login-race-condition
docs/api-reference-update
refactor/payment-modulePrefix with the issue number when one exists — GitHub and GitLab auto-link it and it makes immediately traceable to the tracker. Keep the description under 50 characters — most git UIs truncate branch names in lists around that length. Match the type to the work you're doing — this is the contract readers use to understand the branch purpose at a glance.
git logNEVER include in a branch name — git worktrees are a local checkout mechanism, not a branch concept; the name would leak implementation details into the remote and confuse other contributors.
worktree格式: —— 全部小写,仅使用连字符,除外无特殊字符。
<type>/[issue-]<description>/feat/user-authentication
feat/42-user-authentication
fix/login-race-condition
fix/87-login-race-condition
docs/api-reference-update
refactor/payment-module若存在对应议题编号,需在分支名前缀中加入——GitHub和GitLab会自动关联议题,且能让直接追溯到议题跟踪器。描述部分需控制在50字符以内——大多数Git UI会在列表中截断超过该长度的分支名。分支类型需与工作内容匹配——这是让阅读者一眼理解分支用途的约定。
git log绝对不要在分支名中包含——Git工作区是本地检出机制,不属于分支概念;将其加入远程分支名会暴露实现细节,导致其他贡献者困惑。
worktreeCommit Message Format
提交消息格式
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]Types:
| Type | SemVer | When |
|---|---|---|
| MINOR | New feature |
| PATCH | Bug fix |
| — | Docs only |
| — | Formatting, no logic change |
| — | Restructure, no feature/fix |
| — | Performance improvement |
| — | Add/fix tests |
| — | Build system, deps |
| — | CI config |
| — | Anything else (not src/test) |
| — | Reverts a previous commit |
Rules:
- Subject line ≤ 72 characters — git log and GitHub/GitLab UIs silently truncate longer subjects
- Imperative mood: "add" not "added" — reads as an instruction, not a history log
- No capital letter, no trailing period — enforces uniform parsing by changelog tools
- Body separated by blank line — parsers split header/body at the first blank line
- Breaking changes: use after type/scope, or add
!footer (triggers MAJOR bump) — body-only descriptions are invisible to changelog toolsBREAKING CHANGE: - commits SHOULD include
revertin the body —This reverts commit <hash>.generates this automatically; don't strip itgit revert - NEVER add a Claude signature, AI agent attribution, or trailer for Claude or any other AI agent to commits
Co-authored-by
Examples:
feat(auth): add JWT token refreshfix: prevent race condition on concurrent requests
Introduce request ID and reference to latest request.
Dismiss responses from stale requests.refactor!: drop support for Go 1.18
BREAKING CHANGE: Go 1.18 no longer supported; uses stdlib APIs from 1.21+<type>[可选 scope]: <描述>
[可选正文]
[可选页脚]类型说明:
| 类型 | SemVer 适用版本 | 使用场景 |
|---|---|---|
| MINOR(次版本) | 新增功能 |
| PATCH(修订版) | 修复Bug |
| — | 仅修改文档 |
| — | 代码格式调整,无逻辑变更 |
| — | 代码重构,不新增功能或修复Bug |
| — | 性能优化 |
| — | 添加或修复测试用例 |
| — | 构建系统或依赖项修改 |
| — | CI配置修改 |
| — | 其他非源码/测试相关修改 |
| — | 回滚之前的提交 |
规则要求:
- 主题行长度≤72字符——Git日志及GitHub/GitLab UI会自动截断过长的主题
- 使用祈使语气:用“add”而非“added”——读起来像指令而非历史记录
- 首字母不大写,末尾无句号——确保变更日志工具能统一解析
- 正文与主题行之间用空行分隔——解析器会以第一个空行作为主题与正文的分界
- 破坏性变更:需在类型/scope后加,或添加
!页脚(触发MAJOR主版本升级)——仅在正文中说明的破坏性变更无法被工具识别BREAKING CHANGE: - 类型的提交必须在正文中包含
revert——This reverts commit <hash>.会自动生成该内容,请勿删除git revert - 绝对不要在提交中添加Claude签名、AI Agent归属信息,或为Claude及其他AI Agent添加标记
Co-authored-by
示例:
feat(auth): add JWT token refreshfix: prevent race condition on concurrent requests
Introduce request ID and reference to latest request.
Dismiss responses from stale requests.refactor!: drop support for Go 1.18
BREAKING CHANGE: Go 1.18 no longer supported; uses stdlib APIs from 1.21+Closing Issues via Commit Messages
通过提交消息自动关闭议题
Both GitHub and GitLab detect keywords in commit messages and automatically close the referenced issue when the commit lands on the default branch. Place the reference in the footer (preferred — keeps the subject line clean).
Keywords: , , , , , , , , — case-insensitive.
closeclosesclosedfixfixesfixedresolveresolvesresolvedGitHub:
fix(auth): prevent token expiry race condition
Closes #42
Closes owner/repo#99- Triggers when merged into the default branch (usually )
main - Cross-repo:
Closes owner/repo#42 - Close multiple:
Closes #42, closes #43 - Works in PR descriptions too
GitLab:
feat: add dark mode support
Resolves #101
Closes group/project#42- Triggers when merged into the default branch (configurable per project)
- Cross-project:
Closes group/project#42 - Close multiple:
Closes #101, closes #102 - Works in MR descriptions too
Tip: Pair with the commit type — closing a bug issue, closing a feature request — keeps the changelog semantically coherent.
fix:feat:GitHub和GitLab都会检测提交消息中的关键词,当提交合并到默认分支时,会自动关闭关联的议题。建议将议题引用放在页脚中(可保持主题行简洁)。
支持的关键词: , , , , , , , , ——不区分大小写。
closeclosesclosedfixfixesfixedresolveresolvesresolvedGitHub示例:
fix(auth): prevent token expiry race condition
Closes #42
Closes owner/repo#99- 当合并到默认分支(通常为)时触发
main - 跨仓库关联:
Closes owner/repo#42 - 关闭多个议题:
Closes #42, closes #43 - 在PR描述中使用同样有效
GitLab示例:
feat: add dark mode support
Resolves #101
Closes group/project#42- 当合并到默认分支(可按项目配置)时触发
- 跨项目关联:
Closes group/project#42 - 关闭多个议题:
Closes #101, closes #102 - 在MR描述中使用同样有效
提示: 提交类型与议题类型匹配——用关闭Bug议题,用关闭功能请求议题——可保持变更日志语义连贯。
fix:feat:Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| |
| |
| Subject over 72 chars | Shorten; move detail to body |
| Breaking change only in body | Add |
| |
| Closes #42 in subject line | Move to footer — keeps subject clean and parseable |
| 错误示例 | 修正方案 |
|---|---|
| |
| |
| 主题行超过72字符 | 缩短主题,将细节移至正文 |
| 仅在正文中说明破坏性变更 | 添加 |
| |
| 主题行中包含Closes #42 | 移至页脚——保持主题行简洁可解析 |
Best Practices
最佳实践
- Align branch type and commit type — branch →
feat/auth-*commitsfeat(auth): - One concern per branch — mixing fixes into feature branches obscures the changelog
- Use scope consistently within a branch — throughout, not
feat(auth):mid-wayfeat(user): - Squash merge: when squash-merging a PR/MR, the branch commits are collapsed into one — the PR/MR title becomes the commit message. If the title doesn't follow conventional commits format, changelog generation breaks silently. Always set the PR title before squashing.
- 分支类型与提交类型对齐——分支对应
feat/auth-*类型的提交feat(auth): - 每个分支仅处理一个关注点——在功能分支中混入Bug修复会导致变更日志混乱
- 在分支中统一使用scope——全程使用,不要中途改为
feat(auth):feat(user): - ** squash合并:** 当对PR/MR进行 squash合并时,分支提交会合并为一个——PR/MR标题会成为提交消息。若标题不符合Conventional Commits规范,变更日志生成会静默失败。请务必在squash前设置好PR标题。