目录
Commit message 和 Change log 编写指南
git-commit Angular规范
1、背景
目标
按照一定的规范写 commit messages,可以
在git push
代码之前(工具/脚本自动)检测commit messages。规范提交信息。
规范提交信息的目的:
- 生成 CHANGELOG.md
- 识别不重要的提交
- 在浏览 Git 历史时提供更多信息
在git push
代码之前检测commit messages
的工具(部署在git服务器上,用户每次提交commit messages
都会被检测)
- commitlint
- husky
2、Angular规范
按照Angular规范,commit message 分3个部分:head, body, footer
head: <type> (scop): subject
type: feat, fix, docs, style, refactor, test, chore, revert, perf, build
score: 影响范围
subject: 简短描述(动词开头,首字母小写,结尾不加.)
body: 详细描述
footer: (1) 不兼容改动;(2) 关闭issue
建议
默认情况下,提交消息的最大主题长度为 65,最大行长度为 70。
否则
remote: Counting objects: 119939, done
remote: Processing changes: refs: 1, done
remote: (W) 79e4f24: commit subject >65 characters; use shorter first paragraph
remote: (W) 79e4f24: too many commit message lines longer than 70 characters; manually wrap lines
remote: (W) 092af96: commit subject >65 characters; use shorter first paragraph
remote: (W) 092af96: too many commit message lines longer than 70 characters; manually wrap lines
remote: (W) 07528af: commit subject >65 characters; use shorter first paragraph
remote: (W) 07528af: too many commit message lines longer than 70 characters; manually wrap lines
remote: (W) 5ddf297: commit subject >65 characters; use shorter first paragraph
remote: (W) d3a786b: commit subject >65 characters; use shorter first paragraph
remote: (W) d3a786b: too many commit message lines longer than 70 characters; manually wrap lines
remote: (W) 63f8537: commit subject >65 characters; use shorter first paragraph
remote: (W) 7688c12: commit subject >65 characters; use shorter first paragraph
remote: (W) 7688c12: too many commit message lines longer than 70 characters; manually wrap lines
3、实例
docs(changelog): update changelog to beta.5
fix(release): need to depend on latest rxjs and zone.js
The version in our package.json gets copied to the one we publish, and users need the latest of these.
feat的修改
feat(影响论坛的相关模块):增加点赞功能
(这里是空行)
论坛跟帖增加点赞功能,增加用户体验……
(这里是空行)
解决了名字ID冲突bug
fix的提交
fix(影响论坛的相关模块):修改点赞的bug
(这里是空行)
修改点赞大拇指颜色不变红的bug……
(这里是空行)
close #2143
test的提交
test:增加测试并发登录
(这里是空行)
增加测试并发登录的代码,并发用户量可以设置
docs的提交
docs:增加工程说明文档
(这里是空行)
怎加工程说明文档 《xxxxx工程说明.doc》
……
revert 有特殊的格式
# head: revert: <要被撤销的commit的head>
# body: This reverts commit <commit-hash>.
# eg:
revert: docs add README.md
This reverts commit a2d04c0b914785e4ff0cdf4baeea84d8611c7a61.
例子:
最后生成日志:commit生成Change log。
4、某个博主采用的commit规范
Commit message格式
<type>: <subject>
注意冒号后面有空格。
type
用于说明 commit 的类别,只允许使用下面7个标识。
feat:新功能(feature)
fix:修补bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
test:增加测试chore:构建过程或辅助工具的变动
如果type为feat和fix,则该 commit 将肯定出现在 Change log 之中。
subject
subject是 commit 目的的简短描述,不超过50个字符,且结尾不加句号(.)。
5、提交模板
(git commit 模板配置 https://blog.csdn.net/leibosite/article/details/77993491)