約定式提交
是 git 提交訊息的約定,最有名的規范大概是 Angular 約定
結構
- <> : 必填
- [] : 選填
<type>[scope]: <subject>
[body]
[footer]
// 翻譯
<型別>[范圍]: <描述>
[正文]
[腳注]
type(提交型別)
- feature:新功能
- fix:修復bug
- refactor:保證原功能不變的代碼重構
- perf: 優化性能的代碼更改
- test:測驗
- style: 代碼格式化
- build: 影響構建或外部依賴的更改(gulp, npm,yarn)
- chore:構建程序或輔助工具的變動
- ci: 更改CI組態檔和腳本(Travis、Circle、BrowserStack、SauceLabs)
- docs:專案檔案
- revert: 恢復前一個提交
scope(范圍)
當前 commit 影響的代碼范圍,如:
后端: controller, service, repository
前端: view,api,component
subject
是提交的簡短描述,以動詞開頭
body
是提交的詳細描述
Footer
- 描述不兼容變化
BREAKING CHANGE: [變化]
[變化前后示例]
- 關閉的 issue
Closes #231
工具
Commitizen
是生成約定式提交的工具
安裝
npm install -g commitizen
# 或
yarn global add commitizen
在專案目錄下初始化提交約定
# npm
commitizen init cz-conventional-changelog --save --save-exact
# yarn
commitizen init cz-conventional-changelog --yarn --dev --exact
提交時用 git cz 代替 git commit
@commitlint/cli
檢測提交是否符合約定
安裝
npm install --save-dev @commitlint/cli @commitlint/config-angular
# windows
npm install --save-dev @commitlint/config-conventional @commitlint/cli
// 在專案下配置
echo "module.exports = {extends: ['@commitlint/config-angular']};" > commitlint.config.js
在git提交前檢查
# 安裝 Husky
npm install husky --save-dev
# 或
yarn add husky --dev
# 激活 hooks
npx husky install
# 或
yarn husky install
# 添加 hook
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
standard-version
生成提交歷史工具
安裝
npm install -g standard-version
在專案下運行 standard-version,會生成 CHANGELOG.md 檔案,包含全部提交歷史
一鍵腳本
{
"scripts": {
"release": "standard-version"
}
}
git-commit-message-helper
jetbrains 相關編輯器下的插件

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/297738.html
標籤:其他
上一篇:Docker入門實踐
