husky commitlint commitizen 规范git commit日志
cinob 11/17/2020 git规范
# 配置commitlint
校验commit格式规范
commitlint文档 (opens new window)
安装commitlint(全局)
# npm
npm install -g @commitlint/cli @commitlint/config-conventional
# yarn
yarn global add @commitlint/cli @commitlint/config-conventional
1
2
3
4
5
2
3
4
5
局部安装需要在项目中增加commitlint.config.js
文件
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
1
# 配置husky
提交时自动执行commitlint husky文档 (opens new window)
安装husky
# npm
npm install husky@next --save-dev
# yarn
yarn add husky@next --dev
1
2
3
4
5
2
3
4
5
开启git hooks
# npx
npx husky install
# yarn
yarn husky install
1
2
3
4
5
2
3
4
5
添加husky钩子
# npx
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1'
# yarn
yarn husky add .husky/commit-msg 'yarn commitlint --edit $1'
1
2
3
4
5
2
3
4
5
# 配置commitizen(全局)
帮助提交规范commit commitizen文档 (opens new window)
安装Commitizen cli
工具
# npm
npm install commitizen -g
# yarn
yarn global add commitizen
1
2
3
4
5
2
3
4
5
初始化cz-conventional-changelog
# npm
commitizen init cz-conventional-changelog --save-dev --save-exact
# yarn
commitizen init cz-conventional-changelog --yarn --dev --exact
1
2
3
4
5
2
3
4
5
如果初始化失败可以手动配置 安装
cz-conventional-changelog
# npm npm install cz-conventional-changelog --save-dev # yarn yarn add cz-conventional-changelog -D
1
2
3
4
5在
package.json
中增加"config": { "commitizen": { "path": "cz-conventional-changelog" } }
1
2
3
4
5
使用
# 使用 git cz 替换掉 git commit 命令
git cz
1
2
2
- feat:新功能(feature)
- fix:修补bug
- docs:文档(documentation)
- style: 格式(不影响代码运行的变动)
- refactor:重构(即不是新增功能,也不是修改bug的代码变动)
- test:增加测试
- chore:构建过程或辅助工具的变动