选用当前业界内应用比较普遍的 Angular Git Commit Guidelineshtml
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
复制代码
type
:commit的类型:feat
fix
refactor
docs
style
test
chore
node
scope
:commit 影响的范围, 好比: route, component, utils, build...git
subject
:commit 的概述github
body
:commit 具体修改内容, 能够分为多行npm
footer
:一些备注, 一般是 BREAKING CHANGE 或修复的 bug 的连接json
commitizen/cz-cli, 咱们须要借助它提供的 git cz 命令替代咱们的 git commit 命令, 帮助咱们生成符合规范的 commit message.ide
除此以外, 咱们还须要为 commitizen 指定一个 Adapter 好比: cz-conventional-changelog (一个符合 Angular团队规范的 preset). 使得 commitizen 按照咱们指定的规范帮助咱们生成 commit message.post
yarn add --dev commitizen cz-conventional-changelog
复制代码
package.json中配置:ui
"script": {
...,
"commit": "git-cz",
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
}
复制代码
若是全局安装过 commitizen, 那么在对应的项目中执行 git cz or npm run commit 均可以spa
commitlint: 能够帮助咱们 lint commit messages,校验的配置推荐 @commitlint/config-conventional (符合 Angular团队规范). 话很少说直接按照:
yarn add --dev @commitlint/config-conventional @commitlint/cli
复制代码
同时须要在项目目录下建立配置文件 .commitlintrc.js, 写入:
module.exports = {
extends: [
'@commitlint/config-conventional'
],
rules: {
}
};
复制代码
yarn add --dev husky
复制代码
package.json 中添加:
"husky": {
"hooks": {
...,
"commit-msg": "commitlint -e $GIT_PARAMS"
}
},
复制代码