小編給大家分享一下Commitizen怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)主營(yíng)鼓樓網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP軟件開發(fā),鼓樓h5小程序定制開發(fā)搭建,鼓樓網(wǎng)站營(yíng)銷推廣歡迎鼓樓等地區(qū)企業(yè)咨詢
一、工欲善其事,必先利其器。
大量的代碼提交,必然會(huì)產(chǎn)生大量的commit log,而每一次commit是階段性的Ending,應(yīng)記錄著這一階段所完成的事以及關(guān)注點(diǎn),盡可能詳細(xì)具體;且提供更多的歷史信息,方便快速瀏覽;可以過濾某些commit(比如文檔改動(dòng)),便于快速查找信息;可以直接從commit生成Change log。所以log的格式就是關(guān)鍵所在,而[Commitizen](https://www.npmjs.com/package/commitizen)可以完美的解決這些問題。
二、Commitizen是什么?
是一個(gè)格式化commit message的工具。它的安裝需要[NPM](https://www.npmjs.com/package/npm)的支持,NPM是Node.js的包管理工具,所以首先安裝[node.js](https://nodejs.org/en/download/),下載對(duì)應(yīng)系統(tǒng)的包,安裝即可。
三、Commitizen安裝
npm install -g commitizen
安裝changelog,是生成changelog的工具
npm install -g conventional-changelog npm install -g conventional-changelog-cli
執(zhí)行
npm ls -g -depth=0
檢驗(yàn)上面兩個(gè)工具是否安裝成功,得到結(jié)果如下,表示成功:
/usr/local/lib ├── commitizen@2.9.6 ├── conventional-changelog@1.1.7 ├── conventional-changelog-cli@1.3.5 └── npm@5.5.1
然后,運(yùn)行下面命令,使其支持Angular的Commit message格式。
commitizen init cz-conventional-changelog --save --save-exact
但是注意,因?yàn)閏ommitizen工具是基于Node.js的,而我們iOS項(xiàng)目工程目錄下是沒有package.json文件,所以會(huì)報(bào)錯(cuò):
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'
對(duì)于此種錯(cuò)誤,創(chuàng)建一個(gè)空的package.json文件,然后進(jìn)入到項(xiàng)目目錄,執(zhí)行
npm init --yes
會(huì)生成項(xiàng)目對(duì)應(yīng)項(xiàng)目的package.json,將項(xiàng)目目錄下產(chǎn)生的package.json的內(nèi)容寫入到自己建的package.json(/User/Elite/package.json)中,如果有多個(gè)項(xiàng)目,將各項(xiàng)目生成的package.json內(nèi)容寫入到package.json中,下面是我的配置(/User/Elite/package.json):
[{ "name": "salary", "version": "1.0.0", "description": "> v1.0 涵蓋所有老師(非中教)的基本工資、獎(jiǎng)勵(lì)工資、懲罰工資。", "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" }]
然后進(jìn)入到你要操作的項(xiàng)目目錄,執(zhí)行
conventional-changelog -p angular -i CHANGELOG.md -s
此時(shí)項(xiàng)目中多了CHANGELOG.md文件,表示生成 Change log成功了。以后,凡是用到git commit 命令的時(shí)候統(tǒng)一改為git cz,然后就會(huì)出現(xiàn)選項(xiàng),生成符合格式的Commit Message。實(shí)例如下:
? 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
然后按操作執(zhí)行,即可產(chǎn)生change log。如果最后產(chǎn)生一個(gè)這樣的錯(cuò)誤:
Error: Could not resolve /Users/Elite/web/node_modules/cz-conventional-changelog. Cannot find module '/Users/Elite/web/node_modules/cz-conventional-changelog'
只需做個(gè)軟連接即可:
ln -s /Users/Elite/node_modules /Users/Elite/web/node_modules
當(dāng)然IDE工具下可以裝個(gè)plugin: Git Commit Template
以上是“Commitizen怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!