write-conventional-commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWrite Conventional Commit
编写Conventional Commit提交信息
Generate and apply Conventional Commits that follow the 1.0.0 specification.
生成并遵循1.0.0规范的Conventional Commits提交信息。
Workflow
工作流程
Step 1: Inspect commit scope
步骤1:检查提交范围
Run from repository root:
bash
git status --short
git diff --staged --name-only
git diff --name-onlyUse staged changes when available. If nothing is staged and the user asked to commit now, stage intentionally relevant files first and state what was staged.
从仓库根目录运行:
bash
git status --short
git diff --staged --name-only
git diff --name-only当存在暂存变更时使用暂存内容。如果没有任何内容被暂存且用户要求立即提交,请先暂存相关文件,并说明暂存了哪些内容。
Step 2: Classify intent into commit type
步骤2:将意图分类为提交类型
Pick the best type from change intent, not from file extension.
Common types:
- : add a user-facing feature
feat - : fix a bug
fix - : code change without new feature or bug fix
refactor - : improve performance
perf - : documentation only
docs - : add/update tests
test - : build/dependency tooling
build - : CI/CD configuration
ci - : maintenance that does not fit above
chore - : revert a previous commit
revert
If uncertain between and , prefer:
featfix- when correcting broken behavior
fix - when adding new behavior
feat
根据变更意图选择最合适的类型,而非根据文件扩展名。
常见类型:
- : 添加面向用户的功能
feat - : 修复bug
fix - : 代码变更,既不添加新功能也不修复bug
refactor - : 提升性能
perf - : 仅涉及文档变更
docs - : 添加/更新测试
test - : 构建/依赖工具相关变更
build - : CI/CD配置变更
ci - : 不属于上述类别的维护工作
chore - : 回滚之前的提交
revert
如果在和之间不确定,优先选择:
featfix- 用于修正已损坏的行为
fix - 用于添加新行为
feat
Step 3: Choose optional scope
步骤3:选择可选的范围
Scope is optional and should be short and stable.
Prefer one of:
- top-level package/app (,
api,billing)auth - subsystem (,
migrations,deps)release - user-visible surface (,
checkout)search
Avoid broad scopes like .
misc范围是可选的,应简短且稳定。
优先选择以下类型之一:
- 顶级包/应用(,
api,billing)auth - 子系统(,
migrations,deps)release - 用户可见界面(,
checkout)search
避免使用这类宽泛的范围。
miscStep 4: Detect breaking changes
步骤4:检测破坏性变更
Mark breaking changes when diff indicates incompatible API/contract behavior.
Signals include:
- removed/renamed public endpoints, fields, events, CLI flags
- required inputs changed incompatibly
- output schema changed incompatibly
When breaking:
- Add after type or type+scope (
!orfeat!:)feat(api)!: - Add footer:
BREAKING CHANGE: <what changed and how to migrate>
Use both when possible for clarity.
当差异显示存在不兼容的API/契约行为时,标记破坏性变更。
信号包括:
- 移除/重命名公开端点、字段、事件、CLI标志
- 必填输入发生不兼容变更
- 输出 schema 发生不兼容变更
当存在破坏性变更时:
- 在类型或类型+范围后添加(如
!或feat!:)feat(api)!: - 添加脚注:
BREAKING CHANGE: <变更内容及迁移方式>
尽可能同时使用两者以确保清晰。
Step 5: Compose message in spec format
步骤5:按照规范格式撰写信息
Use this structure exactly:
text
<type>[optional scope][!]: <description>
[optional body]
[optional footer(s)]Formatting rules:
- Header type must be lowercase noun.
- Put a colon and single space after header prefix.
- Keep description concise and specific.
- Put one blank line between header and body.
- Put one blank line between body and footers.
- Footer tokens follow git trailer style (), except references may use
Token: value.Token #value - Use as the canonical breaking footer token.
BREAKING CHANGE:
严格使用以下结构:
text
<type>[optional scope][!]: <description>
[optional body]
[optional footer(s)]格式规则:
- 标题类型必须是小写名词
- 标题前缀后添加冒号和单个空格
- 描述应简洁具体
- 标题和正文之间留一个空行
- 正文和脚注之间留一个空行
- 脚注标记遵循Git尾部格式(),但引用可使用
Token: valueToken #value - 使用作为标准的破坏性变更脚注标记
BREAKING CHANGE:
Step 6: Create commit (when requested)
步骤6:创建提交(当用户要求时)
If user wants the commit executed, run non-interactively:
bash
git commit -m "<header>" -m "<body>" -m "<footer1>" -m "<footer2>"Only include blocks that are needed.
-mFor multiline body/footer with precise formatting, use:
bash
git commit -F /tmp/commit-msg.txtThen report:
- final commit header
- commit hash
- whether breaking change was marked
如果用户要求执行提交,以非交互方式运行:
bash
git commit -m "<header>" -m "<body>" -m "<footer1>" -m "<footer2>"仅包含需要的参数块。
-m对于需要精确格式的多行正文/脚注,使用:
bash
git commit -F /tmp/commit-msg.txt然后报告:
- 最终提交标题
- 提交哈希
- 是否标记了破坏性变更
Quality checks
质量检查
Before finalizing, verify:
- Header matches
<type>[scope][!]: description - Type reflects intent correctly
- Scope is helpful or omitted
- Breaking changes are explicitly marked when applicable
- Body explains why when context is not obvious
- Footers are valid trailers and references are accurate
在最终确定前,验证:
- 标题符合格式
<type>[scope][!]: description - 类型准确反映变更意图
- 范围有帮助或已省略
- 当存在破坏性变更时已明确标记
- 当上下文不明确时,正文解释了变更原因
- 脚注是有效的尾部格式,引用准确
Output behavior
输出行为
When user asks only for message suggestions, provide 1 recommended message and up to 2 alternatives.
When user asks to commit directly, proceed with staging/commit commands and then return commit result.
当用户仅要求提供提交信息建议时,提供1条推荐信息和最多2条备选信息。
当用户要求直接提交时,执行暂存/提交命令,然后返回提交结果。
Reference
参考
Read references/conventional-commits-1.0.0.md for the normative checklist and examples.
阅读references/conventional-commits-1.0.0.md获取规范性检查清单和示例。