Conventional Commits技能使用说明
2026-03-27
新闻来源:网淘吧
围观:16
电脑广告
手机广告
约定式提交
请根据约定式提交规范格式化所有提交信息。这有助于自动生成变更日志、进行语义化版本控制以及维护更清晰的提交历史。
格式结构
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
提交类型
必需类型
feat:- 新增功能(对应语义化版本中的 MINOR)fix:- 修复错误(对应语义化版本中的 PATCH)
常见附加类型
docs:- 仅文档变更style:- 代码风格变更(格式化、缺少分号等)refactor:- 代码重构(不涉及错误修复或新增功能)perf:- 性能优化test:- 添加或更新测试build:- 构建系统或外部依赖变更ci:- CI/CD 配置变更chore:- 不修改源代码或测试文件的其他变更revert:- 撤销之前的提交
作用域
可选的作用域为代码库的特定部分提供额外的上下文信息:
feat(parser): add ability to parse arrays
fix(auth): resolve token expiration issue
docs(readme): update installation instructions
描述
- 必须紧跟在类型/作用域后的冒号和空格之后
- 使用祈使语气(例如"新增功能",而非"新增了功能"或"新增功能")
- 首字母不要大写
- 结尾不要使用句号
- 保持简洁(通常为50-72个字符)
正文
- 可选的更详细描述,提供额外的上下文信息
- 必须在描述后空一行开始
- 可以包含多个段落
- 解释变更的"是什么"和"为什么",而不是"怎么做"
重大变更
重大变更可以通过两种方式标注:
1. 在类型/作用域中使用!2. 使用 BREAKING CHANGE 页脚
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
3. 两种方法同时使用
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
示例
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
始终使用类型
- - 每个提交必须以类型开头,后跟冒号和空格使用祈使语气
- - 写作时想象正在完成这个句子:"如果应用,这个提交将..."具体明确
- - 描述应清晰传达变更内容- The description should clearly communicate what changed
- 保持专注- 每次提交只包含一个逻辑变更
- 在需要时使用作用域- 作用域有助于对代码库中的变更进行分类
- 记录破坏性变更- 始终清晰地标明破坏性变更
语义化版本关联
fix:→ 补丁版本号递增 (1.0.0 → 1.0.1)feat:→ 次版本号递增 (1.0.0 → 1.1.0)- BREAKING CHANGE→ 主版本号递增 (1.0.0 → 2.0.0)
使用场景
此格式适用于:
- 所有git提交
- 提交信息生成
- 拉取请求合并提交
- 当用户询问提交信息或git提交时
常见错误需避免
❌添加了新功能(过去时态,首字母大写)
✅feat: 新增功能(祈使语气,小写)
❌fix: 修复bug(过于模糊)
✅fix: 修复用户服务中的空指针异常
❌feat: 新增功能(冗余)
✅feat: 新增用户资料页
❌feat: 已添加OAuth支持。(过去时态,句号)
✅feat: 添加OAuth支持
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~