规范化 commit message 的作用
- 提供更多的历史信息
- 可以筛选提交内容
- 可以直接从commit生成Change log
下面展示一下小编的 commit message
这是生成的 CHANGELOG
现在开始介绍如何去编写规范的 commit message
git commit message 格式
目前规范使用较多的是 Angular 团队的规范, 继而衍生了 Conventional Commits specification. 很多工具也是基于此规范, 它的 message 格式如下:
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
每个提交消息由header,body和footer组成,其中 body 和 footer 可以省略
Header
header只有一行,包括三个字段:type
(必需)、scope
(可选)和subject
(必需)
type 用于说明 commit 的类别
- feat 一项新功能
- fix 错误修复
- docs 文档
- style 不影响代码含义的更改(空格,格式,缺少分号等)
- refactor 代码更改既不修复错误也不添加功能
- perf: 改进性能的代码更改
- test 添加缺失或更正现有测试
- chore 对构建过程或辅助工具和库(如文档生成)的更改
scope 范围
范围可以是指定提交更改位置的任何内容,可以*
在更改影响多个范围时使用
subject 主题
此次commit的简洁描述,不超过50个字符, 推荐使用英语提交commit。
- 使用命令式,使用"change" 不是 "changed" 也不是 "changes"
- 不要把第一个字母大写
- 最后没有点
.
body 主体
body 部分是对本次 commit 的详细描述,可以分成多行, 比如描述与提交之前有什么不同。
footer 页脚
兼容性
所有重大更改都必须作为页脚中的更改块提及,它应以“BREAKING CHANGE”一词开头:空一到两行。然后,提交消息的其余部分是对更改,理由和迁移说明的描述。
BREAKING CHANGE: isolate scope bindings definition has changed and
the inject option for the directive controller injection was removed.
To migrate the code follow the example below:
Before:
scope: {
myAttr: 'attribute',
myBind: 'bind',
myExpression: 'expression',
myEval: 'evaluate',
myAccessor: 'accessor'
}
After:
scope: {
myAttr: '@',
myBind: '@',
myExpression: '&',
// myEval - usually not useful, but in cases where the expression is assignable, you can use '='
myAccessor: '=' // in directive's template change myAccessor() to myAccessor
}
The removed `inject` wasn't generaly useful for directives so there should be no code using it.
issue
关闭 issus 应该在页脚的单独行中列出,前缀为“Closes”关键字,如下所示:
Closes #234
// 多个
Closes #123, #245, #992
举个栗子
这是我自己项目提交时使用的message, 大家可以参考,下面是手动敲的,可以使用工具 commitizen/cz-cli, 自动生成标准的commit message, 在此不多介绍
feat: write log message into file
Put log message into appoint dir, it will create the dir if not exist
refactor(package.json): update nodejs version and license
The version was 1.0.0, the license was ISC before update, and now, the version is 0.0.1, license is MIT