> For the complete documentation index, see [llms.txt](https://rodneycheung.gitbook.io/handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rodneycheung.gitbook.io/handbook/4.-gui-fan-pian/git_message_regular.md).

# Git message规范

## 背景说明

Git commit message是个非常小的点，很多人都没有关注。实际开发情况中也是在开发项目中写得五花八门。但是项目commit message的规范化会使得项目的提交更加规范化，并且`git log`自带`--grep`选项，可以更好的通过commit message来发现问题。

目前规范使用较多的是[Angular团队的规范](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines)，当前很多github上的项目也是基于此规范。

## 规范说明

```bash
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```

其中`BLANK LINE`指的是空格，所以上面的格式主要分为三部分：

* \\(\\): \ 首行，描述提交的类型，范围和主题
* \ 提交消息主题，详细描述本次提交的内容
* \ 注脚，如Breaking Changes 或 Closed Issues

### type

主要描述commit的类型，主要有如下几个类型

* feat: 新特性
* fix: 修改问题
* refactor: 代码重构
* docs: 文档修改
* style: 代码格式修改
* test: 测试用例修改
* chore: 其他修改, 比如构建流程, 依赖管理.

### scope

主要描述commit的影响范围，主要是影响的相关模块，可选

### subject

commit的主题概述

### body

commit具体修改内容，可以分为多行

### footer

一些备注，可选，通常是BREAKING CHANGE 或修复的 bug 的链接

## git commit 模板

Linux或者MacOS下可以通过git 提交模板来节省记忆成本

### gitmessage

新建`~/.gitmessage`模板，内容如下:

```bash
# head: <type>(<scope>): <subject>
# - type: feat, fix, docs, style, refactor, test, chore
# - scope: can be empty (eg. if the change is a global or difficult to assign to a single component)
# - subject: start with verb (such as 'change'), 50-character line
#
# body: 72-character wrapped. This should answer:
# * Why was this change necessary?
# * How does it address the problem?
# * Are there any side effects?
#
# footer:
# - Include a link to the ticket, if any.
# - BREAKING CHANGE
#
```

### 修改gitconfig

修改`~/.gitcofig`， 添加

```bash
[commit]
template = ~/.gitmessage
```

这样修改完成，在我们每次`git commit`提交是可以看到上面的提交模板
