選用當前業界內應用比較普遍的 Angular Git Commit Guidelineshtml
<type>(<scope>): <subject> <BLANK LINE> <body> <BLANK LINE> <footer>
type
:commit的類型:feat
fix
refactor
docs
style
test
chore
scope
:commit 影響的範圍, 好比: route, component, utils, build...subject
:commit 的概述node
body
:commit 具體修改內容, 能夠分爲多行footer
:一些備註, 一般是 BREAKING CHANGE 或修復的 bug 的連接commitizen/cz-cli, 咱們須要藉助它提供的 git cz 命令替代咱們的 git commit 命令, 幫助咱們生成符合規範的 commit message.git
除此以外, 咱們還須要爲 commitizen 指定一個 Adapter 好比: cz-conventional-changelog (一個符合 Angular團隊規範的 preset). 使得 commitizen 按照咱們指定的規範幫助咱們生成 commit message.github
yarn add --dev commitizen cz-conventional-changelog
package.json中配置:npm
"script": { ..., "commit": "git-cz", }, "config": { "commitizen": { "path": "node_modules/cz-conventional-changelog" } }
若是全局安裝過 commitizen, 那麼在對應的項目中執行 git cz or npm run commit 均可以json
commitlint: 能夠幫助咱們 lint commit messages,校驗的配置推薦 [@commitlint/config-conventional]() (符合 Angular團隊規範).
話很少說直接按照:ide
yarn add --dev @commitlint/config-conventional @commitlint/cli
同時須要在項目目錄下建立配置文件 .commitlintrc.js, 寫入:post
module.exports = { extends: [ '@commitlint/config-conventional' ], rules: { } };
yarn add --dev husky
package.json 中添加:ui
"husky": { "hooks": { ..., "commit-msg": "commitlint -e $GIT_PARAMS" } },