选用当前业界内应用比较普遍的 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" } },