良好的Commit Message有利于代码审查,能更快速查找变更记录,并且可以直接生成Change log。

规范模板

1
2
3
4
5
<Type>(<Scope>): <Subject>
<空行>
<body>
<空行>
<footer>

模板说明

Type(提交类型)

commit的类别,包含以下七种:

  • feat:新功能(feature)
  • fix:修补bug
  • docs:文档(documentation)
  • style: 格式(不影响代码运行的变动)
  • refactor:重构(即不是新增功能,也不是修改bug的代码变动)
  • test:增加测试
  • chore:构建过程或辅助工具的变动

Scope(范围)

commit的影响范围,比如会影响到哪个模块/性能/哪一层(业务层,持久层,缓存,rpc),如果是特性代码,可以写特性名称

Subject(提交主题)

commit的简短描述,不超过50个字符。

  • 使用现在式,祈使句
  • 第一个字母无需大写
  • 结尾不用加句号

Body(内容明细)

跟subject一样,使用现在式,祈使句。应该说明提交代码的动机,以及跟前一个版本的对比。

Footer(页脚)

Foot包含可以包含以下信息:

不兼容变动

以 BREAKING CHANGE 开头,后面是变更的具体描述,如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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.

关闭JIRA

需要与JIRA关联 例如:Closes DB-1001, DB1002

示例

添加用户邮箱字段

1
2
3
feat(用户): 添加字段

添加用户邮箱字段

修复添加用户错误

1
2
3
fix(用户): 修复保存用户错误

修复保存用户错误(邮箱字段长度不足)

插件

IDEA安装Git Commit Template插件