Conventional Commits
Format all commit messages according to the Conventional Commits specification. This enables automated changelog generation, semantic versioning, and better commit history.
Format Structure
CODEBLOCK0
Commit Types
Required Types
- -
feat: - A new feature (correlates with MINOR in Semantic Versioning) fix: - A bug fix (correlates with PATCH in Semantic Versioning)
Common Additional Types
- -
docs: - Documentation only changes style: - Code style changes (formatting, missing semicolons, etc.)refactor: - Code refactoring without bug fixes or new featuresperf: - Performance improvementstest: - Adding or updating testsbuild: - Build system or external dependencies changesci: - CI/CD configuration changeschore: - Other changes that don't modify src or test filesrevert: - Reverts a previous commit
Scope
An optional scope provides additional contextual information about the section of the codebase:
CODEBLOCK1
Description
- - Must immediately follow the colon and space after the type/scope
- Use imperative mood ("add feature" not "added feature" or "adds feature")
- Don't capitalize the first letter
- No period at the end
- Keep it concise (typically 50-72 characters)
Body
- - Optional longer description providing additional context
- Must begin one blank line after the description
- Can consist of multiple paragraphs
- Explain the "what" and "why" of the change, not the "how"
Breaking Changes
Breaking changes can be indicated in two ways:
1. Using ! in the type/scope
CODEBLOCK2
2. Using BREAKING CHANGE footer
CODEBLOCK3
3. Both methods
CODEBLOCK4
Examples
Simple feature
CODEBLOCK5
Feature with scope
CODEBLOCK6
Bug fix with body
CODEBLOCK7
Breaking change
CODEBLOCK8
Documentation update
CODEBLOCK9
Multi-paragraph body with footers
CODEBLOCK10
Guidelines
- 1. Always use a type - Every commit must start with a type followed by a colon and space
- Use imperative mood - Write as if completing the sentence "If applied, this commit will..."
- Be specific - The description should clearly communicate what changed
- Keep it focused - One logical change per commit
- Use scopes when helpful - Scopes help categorize changes within a codebase
- Document breaking changes - Always indicate breaking changes clearly
Semantic Versioning Correlation
- -
fix: → PATCH version bump (1.0.0 → 1.0.1) feat: → MINOR version bump (1.0.0 → 1.1.0)- BREAKING CHANGE → MAJOR version bump (1.0.0 → 2.0.0)
When to Use
Use this format for:
- - All git commits
- Commit message generation
- Pull request merge commits
- When the user asks about commit messages or git commits
Common Mistakes to Avoid
❌ Added new feature (past tense, capitalized)
✅ feat: add new feature (imperative, lowercase)
❌ fix: bug (too vague)
✅ INLINECODE17
❌ feat: add feature (redundant)
✅ INLINECODE19
❌ feat: Added OAuth support. (past tense, period)
✅ INLINECODE21
常规提交
根据常规提交规范格式化所有提交信息。这可以实现自动生成变更日志、语义化版本控制和更好的提交历史记录。
格式结构
<类型>[可选范围]: <描述>
[可选正文]
[可选脚注]
提交类型
必需类型
- - feat: - 新功能(对应语义化版本中的次要版本)
- fix: - 错误修复(对应语义化版本中的补丁版本)
常见附加类型
- - docs: - 仅文档变更
- style: - 代码样式变更(格式化、缺少分号等)
- refactor: - 代码重构,不涉及错误修复或新功能
- perf: - 性能改进
- test: - 添加或更新测试
- build: - 构建系统或外部依赖项变更
- ci: - CI/CD 配置变更
- chore: - 不修改 src 或测试文件的其他变更
- revert: - 回滚之前的提交
范围
可选范围提供关于代码库部分的额外上下文信息:
feat(parser): 添加解析数组的能力
fix(auth): 解决令牌过期问题
docs(readme): 更新安装说明
描述
- - 必须紧跟在类型/范围后的冒号和空格之后
- 使用祈使语气(添加功能而非已添加功能或添加了功能)
- 首字母不大写
- 结尾不加句号
- 保持简洁(通常 50-72 个字符)
正文
- - 提供额外上下文信息的可选较长描述
- 必须在描述后空一行开始
- 可以包含多个段落
- 解释变更的内容和原因,而非方式
破坏性变更
破坏性变更可以通过两种方式表示:
1. 在类型/范围中使用 !
feat!: 产品发货时向客户发送邮件
feat(api)!: 产品发货时向客户发送邮件
2. 使用 BREAKING CHANGE 脚注
feat: 允许提供的配置对象扩展其他配置
BREAKING CHANGE: 配置文件中的 extends 键现在用于扩展其他配置文件
3. 两种方法结合
chore!: 放弃对 Node 6 的支持
BREAKING CHANGE: 使用了 Node 6 中不可用的 JavaScript 功能
示例
简单功能
feat: 添加用户认证
带范围的功能
feat(auth): 添加 OAuth2 支持
带正文的错误修复
fix: 防止请求竞争
引入请求 ID 和对最新请求的引用。忽略来自非最新请求的传入响应。
移除用于缓解竞争问题但现在已过时的超时设置。
破坏性变更
feat!: 迁移到新的 API 客户端
BREAKING CHANGE: API 客户端接口已变更。所有方法现在返回 Promise 而非使用回调。
文档更新
docs: 修正 CHANGELOG 的拼写
带脚注的多段落正文
fix: 防止请求竞争
引入请求 ID 和对最新请求的引用。忽略来自非最新请求的传入响应。
移除用于缓解竞争问题但现在已过时的超时设置。
Reviewed-by: Z
Refs: #123
指南
- 1. 始终使用类型 - 每次提交必须以类型开头,后跟冒号和空格
- 使用祈使语气 - 如同完成句子如果应用此提交,将...
- 具体明确 - 描述应清晰传达变更内容
- 保持专注 - 每次提交只做一个逻辑变更
- 在有用时使用范围 - 范围有助于在代码库中对变更进行分类
- 记录破坏性变更 - 始终清晰标明破坏性变更
语义化版本对应关系
- - fix: → 补丁版本升级(1.0.0 → 1.0.1)
- feat: → 次要版本升级(1.0.0 → 1.1.0)
- BREAKING CHANGE → 主要版本升级(1.0.0 → 2.0.0)
使用时机
在以下情况使用此格式:
- - 所有 git 提交
- 提交信息生成
- 拉取请求合并提交
- 当用户询问关于提交信息或 git 提交时
常见错误避免
❌ Added new feature(过去时,大写)
✅ feat: add new feature(祈使语气,小写)
❌ fix: bug(过于模糊)
✅ fix: resolve null pointer exception in user service
❌ feat: add feature(冗余)
✅ feat: add user profile page
❌ feat: Added OAuth support.(过去时,句号)
✅ feat: add OAuth support