0%

git提交规范

[TOC]

格式

每次提交,都包含三个部分:Header、Body和Footer;

1
2
3
4
5
6
<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>

其中,Header 是必需的,Body 和 Footer 可以省略。
不管是哪一个部分,任何一行都不得超过72个字符(或100个字符)。这是为了避免自动换行影响美观

type

  • 必填
  • 用于说明commit的类型
    • feat:新功能(feature)
    • fix:修补bug
    • docs:文档
    • style:格式
    • refactor:重构
    • test:测试
    • chore:工具变动

type为feat和fix,则该 commit 将肯定出现在 Change log 之中。其他情况(docs、chore、style、refactor、test)由你决定,要不要放入 Change log,建议是不要

scope

  • 可选
  • 用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同

subject

  • 必填
  • commit 目的的简短描述,不超过50个字符
    • 以动词开头,使用第一人称现在时,比如change,而不是changed或changes
    • 第一个字母小写
    • 结尾不加句号

Body

  • 对本次 commit 的详细描述,可以分成多行
  • 应该说明代码变动的动机,以及与以前行为的对比。

只适用两种情况:

  1. 不兼容变动
    如果当前代码与上一个版本不兼容,则 Footer 部分以BREAKING CHANGE开头,后面是对变动的描述、以及变动理由和迁移方法。
1
2
3
4
5
6
7
8
9
10
11
12
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 co...

  1. 关闭Issue
1
Closes #123, #245, #992

Revert

  • 当前 commit 用于撤销以前的 commit,则必须以revert:开头,后面跟着被撤销 Commit 的 Header。

  • Body部分的格式是固定的,必须写成This reverts commit &lt;hash>.,其中的hash是被撤销 commit 的 SHA 标识符。

  • 如果当前 commit 与被撤销的 commit,在同一个发布(release)里面,那么它们都不会出现在 Change log 里面。如果两者在不同的发布,那么当前 commit,会出现在 Change log 的Reverts小标题下面。

1
2
revert: feat(pencil): add 'graphiteWidth' option
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.