在git-commit-message中约束规范message信息,提高message中信息的质量
Commit message 和 Change log 编写指南 (opens new window)
# 模块配置
# commitizen
提供定制化的,提交信息规范,系统会提示您在提交时填写所有必需的提交字段。不再等到以后再运行
git commit钩子并拒绝您的提交
# 安装
如果你的npm<5.2则需要全局安装
npm install -g commitizen
如果你使用npm 5.2+,则可以使用局部安装,然后使用一下命令运行
npx git-cz
# 配置提示规则
# 引用规则
npm
commitizen init cz-conventional-changelog --save-dev --save-exact
yarn
commitizen init cz-conventional-changelog --yarn --dev --exact
并在package.json中配置
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
}
# 自定义规则
需要借助cz-customizable (opens new window)
# commitlint
制定
commit信息规范,对commit信息进行校验,如果不满足,则不允许提交
# 安装
# Install commitlint cli and conventional config
npm install --save-dev @commitlint/{config-conventional,cli}
# For Windows:
npm install --save-dev @commitlint/config-conventional @commitlint/cli
# 配置
# 引用规则
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
# 自定义规则
rule 由 name 和配置数组组成,如:'name:[0, 'always', 72]'
- level:可选
0,1,2,0 为 disable,1 为 warning,2 为 error - Applicable:
always|never是否应用 - Value:此规则需要匹配的值
具体规则配置见
配置规则的同时还需要注意commitlint 解析器预设 (opens new window)能否正常解析
# Husky
这使我们可以通过 husky.hooks 字段将 git 钩子直接添加到 package.json 中。
# 安装
npm install -D husky
# 配置
在package.json中添加挂钩
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
# cz-customizable
可定制的
Commitizen插件
# 安装
npm install cz-customizable --save-dev
# 配置
在package.json中配置
"config": {
"commitizen": { // not needed for standlone usage
"path": "node_modules/cz-customizable"
},
// 配置文件路径,默认配置文件为根目录下的.cz-config.js文件
"cz-customizable": {
"config": "config/path/to/my/config.js"
}
# 配置规则
- subjectLimit:header 的长度
- types:自定义
type类型选项
types: [{
value: '新功能',
name: '新功能 : 新增加一个功能'
},
{
value: '修复',
name: '修复 : 一个 bug 修复'
},
{
value: '优化',
name: '优化 : 提升性能的代码更改'
},
{
value: '重构',
name: '重构 : 不涉及修复bug和新功能开发的代码更改'
},
{
value: '文档',
name: '文档 : 只有文档发生改变'
},
{
value: '构建',
name: '构建 : 修改持续集成的配置文件和脚本'
},
{
value: '撤销',
name: '撤销 : 撤销一个历史提交'
}
]
- scopes:自定义
scopes类型选项
scopes: [{
name: '小'
}, {
name: '中'
}, {
name: '大'
}, {
name: '全局'
}]
- scopeOverrides:针对每个
type可以自定义对应的scope
scopeOverrides: {
fix: [
{name: 'merge'},
{name: 'style'},
{name: 'e2eTest'},
{name: 'unitTest'}
]
}
- allowBreakingChanges:需要填写影响范围的类型
- skipQuestions:跳过的问题列表
- footerPrefix:自定义页脚前缀
- breaklineChar:自定义换行字符串