关于 conventional-commits
面向开发者和 Agent 的提交信息规范技能,依据 Conventional Commits 统一提交格式。内容涵盖类型、作用域、破坏性变更标记及描述规范。
主要功能
- 01Conventional Commits 信息结构
- 02提交类型与可选作用域
- 03破坏性变更标记
- 04祈使式简洁描述
- 05与语义化版本的关联
适用场景
- 01编写一致的 Git 提交信息
- 02准备合并提交信息
- 03生成适合变更日志的提交
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ bastos/ skills --skill conventional-commits安装后在 Claude Code 中输入/conventional-commits确认已加载。
详细介绍
Conventional Commits
根据 Conventional Commits 规范编写所有提交消息。这样可以自动生成变更日志、进行语义化版本控制,并使提交历史更清晰。
格式结构
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
提交类型
映射到 SemVer 的核心类型
当变更符合以下类型时,请使用它们;在规范中,只有这些类型具有隐含的 SemVer 含义:
feat:- 新功能(对应语义化版本控制中的 MINOR)fix:- 错误修复(对应语义化版本控制中的 PATCH)
常见的其他类型
docs:- 仅修改文档style:- 代码风格变更(格式调整、缺少分号等)refactor:- 重构代码,不涉及错误修复或新功能perf:- 性能改进test:- 添加或更新测试build:- 构建系统或外部依赖项变更ci:- CI/CD 配置变更chore:- 其他不修改 src 或 test 文件的变更revert:- 撤销之前的提交
作用域
可选的作用域用于提供有关代码库中相关部分的更多上下文:
feat(parser): add ability to parse arrays
fix(auth): resolve token expiration issue
docs(readme): update installation instructions
描述
- 必须紧跟在类型/作用域后面的冒号和空格之后
风格建议:
- 使用祈使语气(“add feature”,而非“added feature”或“adds feature”)
- 首字母不要大写
- 末尾不要加句号
- 尽量不超过 72 个字符(包括类型和作用域)
- 建议不超过 50 个字符,以提高可读性
正文
- 可选的较长描述,用于提供更多上下文
- 必须在描述之后空一行
- 可以包含多个段落
- 说明变更的“内容”和“原因”,而非“方式”
破坏性变更
可以通过两种方式标明破坏性变更:
1. 在类型/作用域中使用 !
feat!: send an email to the customer when a product is shipped
feat(api)!: send an email to the customer when a product is shipped
2. 使用 BREAKING CHANGE 页脚
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
规范也将 BREAKING-CHANGE: 视为同义的页脚标记;除非项目约定另有规定,否则优先使用 BREAKING CHANGE:。
3. 同时使用两种方式
chore!: drop support for Node 6
BREAKING CHANGE: use JavaScript features not available in Node 6.
示例
简单功能
feat: add user authentication
带作用域的功能
feat(auth): add OAuth2 support
带正文的错误修复
fix: prevent racing of requests
Introduce a request id and a reference to latest request. Dismiss
incoming responses other than from latest request.
Remove timeouts which were used to mitigate the racing issue but are
obsolete now.
破坏性变更
feat!: migrate to new API client
BREAKING CHANGE: The API client interface has changed. All methods now
return Promises instead of using callbacks.
文档更新
docs: correct spelling of CHANGELOG
带页脚的多段正文
fix: prevent racing of requests
Introduce a request id and a reference to latest request. Dismiss
incoming responses other than from latest request.
Remove timeouts which were used to mitigate the racing issue but are
obsolete now.
Reviewed-by: Z
Refs: #123
指南
- 始终使用类型 - 每次提交都必须以类型开头,后跟冒号和空格
- 使用祈使语气 - 仿照句子“If applied, this commit will...”来编写
- 具体明确 - 描述应清楚说明变更内容
- 聚焦变更 - 每次提交只包含一项逻辑变更
- 适时使用作用域 - 作用域有助于对代码库中的变更进行分类
- 记录破坏性变更 - 始终清楚地标明破坏性变更
与语义化版本控制的对应关系
fix:→ PATCH 版本递增(1.0.0 → 1.0.1)feat:→ MINOR 版本递增(1.0.0 → 1.1.0)- BREAKING CHANGE → MAJOR 版本递增(1.0.0 → 2.0.0)
适用场景
在以下场景中使用此格式:
- 所有 git 提交
- 生成提交消息
- Pull Request 合并提交
- 用户询问提交消息或 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
评论
支持 Markdown