Git Commit规范化¶
概要: 基于Angular git commit style,写出清晰易懂的git commit message
创建时间: 2022.05.19 01:09:46
更新时间: 2022.10.10 21:22:48
基本格式¶
三部分组成,即head
标题,body
主体和footer
备注
head部分¶
type
: 提交修改的类型feat
: new feature, 新功能fix
: fix bug, 修复故障docs
: update documentation, 更新文档style
: code style, 代码格式优化,如删除多余的空格空行refactor
: code refactor, 代码重构,无增删功能和故障修复perf
: improve performance, 提升代码性能test
: add or correct testcase, 增加或纠正测试用例ci
: CI工具方法或配置的变动scope
: 提交修改的影响范围/模块,如UI, DB, API, UT, FT, ST, module-A, module-B等subject
: 简述本次改动的内容(英语字符50个以内,汉字20个以内),结尾无标点符号.
或者。
body部分¶
Explain the motivation for the change in the commit message body. This commit message should explain why you are making the change. You can include a comparison of the previous behavior with the new behavior in order to illustrate the impact of the change.
主体部分主要解释提交此变更的具体动机和原因,可以增加与修改前的对比来凸显变更的必要性(英语需要使用一般现在时进行表述)
footer部分¶
The footer can contain information about breaking changes and deprecations and is also the place to reference GitHub issues, Jira tickets, and other PRs that this commit closes or is related to.
备注/结语部分主要用来:
- 描述对项目造成的重大影响
- 描述是否有类/方法/变量已废弃
- 描述是否关闭了某个
issue
- 描述是否合入了某个
PR
或者MR
有重大变更...
Text Only | |
---|---|
废弃了某个接口/类/方法...
Text Only | |
---|---|
代码回退场景¶
默认使用git revert ${commit-id}
命令生成的格式即可,示例如下
Text Only | |
---|---|
提交信息示例¶
从Angular项目扒取的一个commit如下
Text Only | |
---|---|
commit格式化工具¶
基于macOS平台,使用commitizen工具来规范自己的git commit,其它平台请参考Commitizen by commitizen
安装commitizen¶
使用brew
安装commitizen如下
Bash | |
---|---|
使用commitizen¶
执行git cz
或者cz --help
查看commitizen的使用帮助,下面是一些高频命令。
使用自定义的git commit规范¶
Bash | |
---|---|
初始化项目git commit规范¶
按照提示完成配置后,即可生成对应的项目cz配置文件.cz.yaml
使用cz编写commit¶
在git add file1 file2 ...
后,执行cz c
或者git cz c
即可进入交互式终端
最后即可生成符合规范的commit
使用cz生成changelog¶
执行cz ch
或者git cz ch
即可自动生成CHANGELOG.md
文件(此操作将会覆盖旧的changelog)
其它cz命令¶
cz -n ${cz_template}
: 使用特定名称的cz规范模版cz ls
: 显示当前cz example
: 给出一个符合cz规范的commit示例cz info
: 告诉你cz是什么cz schema
: 显示当提交规范的格式cz check -m ${commit_msg}
: 检查此条commit message是否符合cz规范cz version
: 显示cz当前版本