# Git Commit Message规范

```shell
git commit -m "commit message" # 直接加描述
git commit # 编辑器描述
```

## Commit Message 格式

每次提交，Commit message 都包括三个部分：Header，Body 和 Footer：

```
<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>
```

## type

1. `feat`：新功能（feature）
2. `fix`：修补bug
3. `docs`：文档（documentation）
4. `style`： 格式（不影响代码运行的变动）
5. `refactor`：重构（即不是新增功能，也不是修改bug的代码变动）
6. `test`：增加测试
7. `chore`：构建过程或辅助工具的变动，比如添加依赖、更新依赖版本

如果type为`feat`或者`fix`，则该commit将肯定出现在 Change log 之中。 如果为其他为type，`docs`、`chore`、`style`、`refactor`、`test`，需要根据情况决定是否放入`Change Log`，建议是不要。

## scope

`scope` 用于说明 `commit` 影响的范围，比如

1. 数据层
2. 控制层
3. 视图层

等等，视项目不同而不同。

## subject

`subject` 是 commit 目的的简短描述，不超过50个字符。

1. 以动词开头，使用第一人称现在时，比如 change xxx，而不是 xxx changed的
2. 第一个字母小写
3. 结尾不加句号 (.)

## body

Body 部分是对本次 commit 的详细描述，可以分成多行

## footer

footer只适用于两种情况:

1. 不兼容变动, 如果当前代码与上一个版本不兼容，则 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.
   ```
2. 关闭issue

   ```
   Closes #123, #245, #992
   ```

## revert (特殊情况-撤销)

还有一种特殊情况，如果当前 commit 用于撤销以前的 commit，则必须以 `revert:` 开头，后面跟着被撤销 Commit 的 Header：

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

## 示例

```shell
# 一次简单的功能性提交，没有具体描述
feat: allow provided config object to extend other configs

# 增加!,代表此次提交时突破性提交，变动比较大
feat!: send an email to the customer when a product is shipped

# 增加范围
feat(api)!: send an email to the customer when a product is shipped
```
