Commit Message 作用
每次 git commit 时,都需要编写相应的说明,否则是不允许提交的。
commit message 应该清晰明了的说明本次提交的目的。
规范的 commit message 有利于:
- 对 git log 进行分析和查找
- 也有利用使用工具进行格式化的文档生成
Angular 规范写法
每次提交,Commit message 都应当包括三个部分:Header,Body 和 Footer。
<type>: <subject>
// 空一行
<body>
// 空一行
<footer>
不管是哪一个部分,任何一行都不得超过72个字符(或100个字符)。这是为了避免自动换行影响美观。
type
type用于说明 commit 的类别,只允许使用下面7个标识。
- feat:新功能(feature)
- fix:修补bug
- docs:文档(documentation)
- style: 格式(不影响代码运行的变动)
- refactor:重构(即不是新增功能,也不是修改bug的代码变动)
- test:增加测试
- chore:构建过程或辅助工具的变动
subject
subject 是 commit 目的的简短描述,不超过50个字符。
- 以动词开头,使用第一人称现在时
- 第一个字母小写
- 结尾不加句号(. / 。)
body
Body 部分是对本次 commit 的详细描述,可以分成多行。下面是一个范例。
More detailed explanatory text, if necessary. Wrap it to
about 72 characters or so.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Use a hanging indent
Footer
Footer 部分只用于两种情况。
不兼容变动
如果当前代码与上一个版本不兼容,则 Footer 部分以BREAKING CHANGE开头,后面是对变动的描述、以及变动理由和迁移方法。
BREAKING CHANGE: isolate scope bindings definition has changed.
To migrate the code follow the example below:
Before:
scope: {
myAttr: 'attribute',
}
After:
scope: {
myAttr: '@',
}
The removed `inject` wasn't generaly useful for directives so there should be no code using it.
关闭 Issue
如果当前 commit 针对某个issue,那么可以在 Footer 部分关闭这个 issue 。
Closes #123, #245, #992
revert
还有一种特殊情况,如果当前 commit 用于撤销以前的 commit,则必须以revert:开头,后面跟着被撤销 Commit 的 Header。
revert: feat(pencil): add 'graphiteWidth' option
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
Commit Message 编写辅助工具
Commitizen 是一个撰写合格 Commit message 的工具。
可以使用该工具帮助编写符合格式的 commit 信息
Change log 生成工具
如果你的所有 Commit 都符合 Angular 格式,那么发布新版本时, Change log 就可以用脚本自动生成,生成的文档包括以下三个部分。
- New features
- Bug fixes
- Breaking changes.
可以使用辅助工具 conventional-changelog 生成 Change log