對于git送出規範 來說,不同的團隊可能會有不同的标準
我們要學習的commitizen就是其中的佼 佼者!commitizen倉庫名為 ,它提供了個git cz的指令于代替git commit,簡單句話介紹它: 當你使commitizen進代碼送出(git commit)時,commitizen會送出你在送出時填寫所有必需的提 交字段!這句話怎麼解釋呢?不着急,下我們就來安裝并且使下commitizen,使完成之後你然就明 了這句話的意思!
全局安裝把:
npm install -g [email protected]
然後安裝和配置 cz-customizable 插件
npm i [email protected] --save-dev
添加以下配置到 package.json 中
"config": {
"commitizen":{
"path":"node_modules/cz-customizable"
}
}
View Code
然後項根錄下建立.cz-config.js自定義送出内容
module.exports = {
// 可選類型
types: [
{ value: 'feat', name: 'feat: 新功能' },
{ value: 'fix', name: 'fix: 修複' },
{ value: 'docs', name: 'docs: 文檔變更' },
{ value: 'style', name: 'style: 代碼格式(不影響代碼運作的變動)' },
{
value: 'refactor',
name: 'refactor: 重構(既不是增加feature,也不是修複bug)'
},
{ value: 'perf', name: 'perf: 性能優化' },
{ value: 'test', name: 'test: 增加測試' },
{ value: 'chore', name: 'chore: 建構過程或輔助工具的變動' },
{ value: 'revert', name: 'revert: 回退' },
{ value: 'build', name: 'build: 打包' }
],
// 消息步驟
messages: {
type: '請選擇送出類型:',
customScope: '請輸入修改範圍(可選):',
subject: '請簡要描述送出(必填):',
body: '請輸入較長的描述(可選):',
footer: '請輸入要關閉的issue(可選):',
confirmCommit: '确認使用以上資訊送出?(y/n/e/h)'
},
// 跳過問題
skipQuestions: ['body', 'footer'],
// subject文字長度預設是72
subjectLimit: 72
}
View Code
然後我們就可以嘗試
git add .
git cz
我們 git cz 是代替了 git commit -m 'xxx'
他會問你一堆東西,其實就是你自己配置的。
如果你忘記了用 git cz 送出咋個辦? 解決方法來了:GITHOOKS:
git 鈎子嘛。。。
阻止不合規的Git送出資訊,那麼就攔截報錯。
主要用的就2個: