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