在团队协做开发时,每一个人提交代码时都会写 commit message。webpack
每一个人都有本身的书写风格,翻看咱们组的git log, 能够说是五花八门,十分不利于阅读和维护。git
通常来讲,大厂都有一套的本身的提交规范,尤为是在一些大型开源项目中,commit message 都是十分一致的。github
所以,咱们须要制定统一标准,促使团队造成一致的代码提交风格,更好的提升工做效率,成为一名有追求的工程师。web
AngularJS 在 github上 的提交记录被业内许多人承认,逐渐被你们引用。npm
type(scope) : subject
( 1 ) type(必须) : commit 的类别,只容许使用下面几个标识:gulp
( 2 ) scope(可选) : 用于说明 commit 影响的范围,好比数据层、控制层、视图层等等,视项目不一样而不一样。vim
( 3 ) subject(必须) : commit 的简短描述,不超过50个字符。
commitizen 是一个撰写合格 Commit message 的工具,
遵循 Angular 的提交规范。性能优化
全局安装 commitizen编辑器
npm install -g commitizen
进入项目文件夹,运行以下命令:grunt
commitizen init cz-conventional-changelog --save --save-exact
用 git cz
命令取代 git commit
(先使用git add),这时会出现以下选项:
( 1 )选择 type
( 2 )填写 scope(选填)
? What is the scope of this change (e.g. component or file name)? (press enter to skip) core
( 3 )填写 subject
? Write a short, imperative tense description of the change: set a to b
完成,运行 git log
命令,查看咱们刚才提交的 commit message,以下:
fix(core): set a to b
步骤以下:
在项目中创建 .git_template 文件,内容能够自定义:
type: scope: subject:
运行以下命令:
git config commit.template .git_template // 当前项目 <!-- git config commit.template .git_template // 全局设置 -->
先使用 git add
添加代码
使用 git commit
按照模板填写
最后 git push
推送到远端
第二章中提到的两种业内广泛使用的规范,都不彻底适合咱们。
第一种方式适合大型开源项目,咱们若是也照搬会比较麻烦,但咱们能够借鉴 type(scope): subject 的提交格式,也算是与大厂同步;
第二种方式虽然自由,可是也不比较麻烦,要配置模板。
所以,咱们只模仿 type(scope): subject 的提交格式,不使用工具 or 模板校验,靠你们自觉遵照便可。
type: description
type 是 commit 的类别,只容许以下几种标识:
description 是对本次提交的简短描述。
不超过50个字符。
推荐以动词开头,如: 设置、修改、增长、删减、撤销等