Git Commit Message 提交规范配置说明

描述
针对 git commit log 提交规范的问题,需要统一规范,不然很容易造成误解。
Commitizen: 替代你的 git commit
全局安装
npm install -g commitizen
项目级安装
npm install -D commitizen cz-customizable --dev
package.json
中配置:
"config": {
"commitizen": {
"path": "node_modules/cz-customizable"
}
},
配置规则
.cz-config.js 中写入自定义的配置:
'use strict'
module.exports = {
types: [
{
value: '💪 WIP',
name: '进度: 工作进度',
},
{
value: '✨ feat',
name: '功能: 新功能',
},
{
value: '🐞 fix',
name: '修复: 修复bug',
},
{
value: '🛠 refactor',
name: '重构: 代码重构',
},
{
value: '📚 docs',
name: '文档: 只有文档变更',
},
{
value: '🏁 test',
name: '测试: 添加一个测试',
},
{
value: '🗯 chore',
name: '工具: 没有修改源代码,只是变更构建流程或辅助工具。',
},
{
value: '💅 style',
name: '样式: 空格,分号等格式修复。',
},
{
value: '⏪ revert',
name: '回滚: 代码回退。',
},
{
value: '🏎 perf',
name: '性能: 提升性能。',
},
{
value: '🏗 build',
name: '构建: 变更项目构建或外部依赖(例如scopes: webpack、gulp、npm等)',
},
{
value: '🕹 ci',
name:
'集成: 更改持续集成软件的配置文件和package中的scripts命令,例如scopes: Travis, Circle等',
},
],
scopes: [],
messages: {
type: '选择一种你的提交类型:',
scope: '选择一个scope (可选):',
// used if allowCustomScopes is true
customScope: 'Denote the SCOPE of this change:',
subject: '短说明:\n',
body: '长说明,使用"|"换行(可选):\n',
breaking: '非兼容性说明 (可选):\n',
footer: '关联关闭的issue,例如:#31, #34(可选):\n',
confirmCommit: '确定提交说明?',
},
footerPrefix: 'TAPD: ',
allowCustomScopes: true,
allowBreakingChanges: ['特性', '修复'],
skipQuestions: ['scope', 'body', 'footer'],
}
效果如下:

Commitlint: 校验你的 message
commitlint: 可以帮助我们 lint commit messages, 如果我们提交的不符合指向的规范, 直接拒绝提交。
yarn add commitlint-config-cz @commitlint/cli --dev
.commitlintrc.js 中写入:
module.exports = {
extends: [
'cz'
],
rules: {
}
};
结合 Husky
校验 commit message 的最佳方式是结合 git hook, 所以需要配合 Husky。
npm i husky@next
package.json 中添加:
"husky": {
"hooks": {
...,
"commit-msg": "commitlint -e $GIT_PARAMS"
}
},