小編給大家分享一下Commitizen怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

一、工欲善其事,必先利其器。
大量的代碼提交,必然會產生大量的commit log,而每一次commit是階段性的Ending,應記錄著這一階段所完成的事以及關注點,盡可能詳細具體;且提供更多的歷史信息,方便快速瀏覽;可以過濾某些commit(比如文檔改動),便于快速查找信息;可以直接從commit生成Change log。所以log的格式就是關鍵所在,而[Commitizen](https://www.npmjs.com/package/commitizen)可以完美的解決這些問題。
二、Commitizen是什么?
是一個格式化commit message的工具。它的安裝需要[NPM](https://www.npmjs.com/package/npm)的支持,NPM是Node.js的包管理工具,所以首先安裝[node.js](https://nodejs.org/en/download/),下載對應系統的包,安裝即可。
三、Commitizen安裝
npm install -g commitizen
安裝changelog,是生成changelog的工具
npm install -g conventional-changelog npm install -g conventional-changelog-cli
執行
npm ls -g -depth=0
檢驗上面兩個工具是否安裝成功,得到結果如下,表示成功:
/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格式。
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
以上是“Commitizen怎么用”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯行業資訊頻道!
另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
標題名稱:Commitizen怎么用-創新互聯
網頁鏈接:http://www.yijiale78.com/article46/cchheg.html
成都網站建設公司_創新互聯,為您提供網站設計、網站排名、ChatGPT、定制開發、網站設計公司、品牌網站制作
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯