# 优雅的提交你的 Git Commit Message
# Commit message 的作用
- 提供更多的历史信息,方便快速浏览。
- 可以过滤某些 commit(比如文档改动),便于快速查找信息。
git log <last release> HEAD --grep feature
1
- 可以直接从 commit 生成 Change log。
# Commit Message 格式
Commitizen 是一个撰写合格 Commit message 的工具。
- 项目级安装
yarn add commitizen cz-conventional-changelog --dev
1
- 之后在 package.json添加脚本"commit": "git-cz"
{
  "script": {
    // ...,
    "commit": "git-cz"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 自定义 Adapter
也许 Angular 的那套规范我们不习惯, 那么可以通过指定 Adapter cz-customizable 指定一套符合自己团队的规范。
- 全局 或 项目级别安装:
yarn add global cz-customizable
or
yarn add cz-customizable --dev
1
2
3
2
3
- 修改 .czrc 或 package.json 中的 config 为:
{ "path": "cz-customizable" }
or
  "config": {
    "commitizen": {
      "path": "node_modules/cz-customizable"
    }
  }
1
2
3
4
5
6
7
2
3
4
5
6
7
- 同时在~/ 或项目目录下创建 .cz-config.js 文件, 维护你想要的格式,如
'use strict';
module.exports = {
  types: [
    {
      value: 'feat',
      name : 'feat:     A new feature'
    },
    {
      value: 'fix',
      name : 'fix:      A bug fix'
    },
    {
      value: 'refactor',
      name : 'refactor: A code change that neither fixes a bug nor adds a feature'
    },
    {
      value: 'docs',
      name : 'docs:     Documentation only changes'
    },
    {
      value: 'test',
      name : 'test:     Add missing tests or correcting existing tests'
    },
    {
      value: 'chore',
      name : 'chore:    Changes that don\'t modify src or test files. Such as updating build tasks, package manager'
    },
    {
      value: 'style',
      name : 'style:    Code Style, Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)'
    },
    {
      value: 'revert',
      name : 'revert:   Revert to a commit'
    },
    {
      value: 'version',
      name: 'version: 发版本用的'
    }
  ],
  scopes: ["一张图","辅助审批","辅助审查","辅助编制","监测预警","公共模块","行业管理","cli","版本更新"],
  allowCustomScopes: true,
  allowBreakingChanges: ["feat", "fix"]
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48