commit 之 Angular 規範
1、commit 基本類型:
feat
: 新功能(feature)fix
: 修改bugdocs
: 文檔(documentation)style
: 格式(不影響代碼運行的變動)refactor
: 重構(即不是新增功能,也不是修改bug的代碼變動)test
: 增加測試chore
: 構建過程或輔助工具的變動
2、commit 基本結構:
<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>
type
commit 的類型。scope
用於說明 commit 影響的範圍,比如數據層、控制層、視圖層等等,視項目不同而不同。subject
commit目的的簡短描述,不多於50字。body
是本次提交詳細的描述,格式是與 type 空一行,與下面的 footer 也空一行。footer
一般描述不兼容情況和關閉的 issues。
3、安裝 commitizen 簡化提交方式
nmp install -g commitizen
安裝完成後便可以額使用 git cz
替代 git commit
4、安裝工具檢測提交是否合乎規範
- install commitlint
npm init
npm install --save-dev @commitlint/{cli,config-conventional}
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js
- install husky
npm install --save-dev husky
package.json 文件裏面插入:
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
注意:
- 少量多次提交,方便 review,一次修改比較大,應對相關修改分類,分多次提交。
- 修改 bug 可以將 jira 相關的問題的代號關聯。