1、工欲善其事,必先利其器。node
大量的代码提交,必然会产生大量的commit log,而每一次commit是阶段性的Ending,应记录着这一阶段所完成的事以及关注点,尽量详细具体;且提供更多的历史信息,方便快速浏览;能够过滤某些commit(好比文档改动),便于快速查找信息;能够直接从commit生成Change log。因此log的格式就是关键所在,而[Commitizen](https://www.npmjs.com/package/commitizen)能够完美的解决这些问题。git
2、Commitizen是什么?web
是一个格式化commit message的工具。它的安装须要[NPM](https://www.npmjs.com/package/npm)的支持,NPM是Node.js的包管理工具,因此首先安装[node.js](https://nodejs.org/en/download/),下载对应系统的包,安装便可。npm
3、Commitizen安装json
npm install -g commitizen
安装changelog,是生成changelog的工具bash
npm install -g conventional-changelog npm install -g conventional-changelog-cli
执行app
npm ls -g -depth=0
检验上面两个工具是否安装成功,获得结果以下,表示成功:composer
/usr/local/lib ├── commitizen@2.9.6 ├── conventional-changelog@1.1.7 ├── conventional-changelog-cli@1.3.5 └── npm@5.5.1
而后,运行下面命令,使其支持Angular的Commit message格式。ide
commitizen init cz-conventional-changelog --save --save-exact
可是注意,由于commitizen工具是基于Node.js的,而咱们iOS项目工程目录下是没有package.json文件,因此会报错:工具
npm WARN saveError ENOENT: no such file or directory, open '/Users/Elite/package.json' npm WARN enoent ENOENT: no such file or directory, open '/Users/Elite/package.json'
对于此种错误,建立一个空的package.json文件,而后进入到项目目录,执行
npm init --yes
会生成项目对应项目的package.json,将项目目录下产生的package.json的内容写入到本身建的package.json(/User/Elite/package.json)中,若是有多个项目,将各项目生成的package.json内容写入到package.json中,下面是个人配置(/User/Elite/package.json):
[{ "name": "salary", "version": "1.0.0", "description": "> v1.0 涵盖全部老师(非中教)的基本工资、奖励工资、惩罚工资。", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git@***.***.com:erp/salary.git" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "cz-conventional-changelog": "^2.1.0" }, "config": { "commitizen": { "path": "./node_modules/cz-conventional-changelog" } }, "dependencies": {} }, { "name": "ats", "version": "1.0.0", "description": "composer.json composer配置 vendor 第三方类库", "main": "index.js", "directories": { "test": "tests" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git@***.***.com:ats/ats.git" }, "keywords": [], "author": "", "license": "ISC" }]
而后进入到你要操做的项目目录,执行
conventional-changelog -p angular -i CHANGELOG.md -s
此时项目中多了CHANGELOG.md文件,表示生成 Change log成功了。之后,凡是用到git commit 命令的时候统一改成git cz,而后就会出现选项,生成符合格式的Commit Message。实例以下:
? Select the type of change that you're committing: (Use arrow keys) ❯ feat: A new feature fix: A bug fix docs: Documentation only changes style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) refactor: A code change that neither fixes a bug nor adds a feature perf: A code change that improves performance test: Adding missing tests or correcting existing tests
而后按操做执行,便可产生change log。若是最后产生一个这样的错误:
Error: Could not resolve /Users/Elite/web/node_modules/cz-conventional-changelog. Cannot find module '/Users/Elite/web/node_modules/cz-conventional-changelog'
只需作个软链接便可:
ln -s /Users/Elite/node_modules /Users/Elite/web/node_modules
固然IDE工具下能够装个plugin: Git Commit Template