一、全局安装 Commitizen
npm i commitizen -g
二、项目中安装适配器 cz-customizable
npm i cz-customizable --save-dev
三、适配器配置
commitizen init cz-customizable --save --save-exact
四、自定义交互提示
默认的Commitizen的交互信息是英文的,我们可以在.cz-config.js文件中自定义交互内容
// 在根目录下创建.cz-config.js
module.exports = {
types: [
{
value: 'fix',
name: 'fix: 优化,或修复一个bug',
},
{
value: 'feat',
name: 'feat: 新增一个功能',
},
{
value: 'update',
name: 'update: 代码打包提交',
},
{
value: 'build',
name: 'build: 变更项目构建或外部依赖(如scopes: webpack、npm等)',
},
{
value: 'perf',
name: 'perf: 性能优化',
},
{
value: 'docs',
name: 'docs: 文档变更',
},
{
value: 'revert',
name: 'revert: 代码回退',
},
{
value: 'refactor',
name: 'refactor: 代码重构',
},
{
value: 'test',
name: 'test: 添加一个测试',
},
],
messages: {
type: '选择一种你期望的提交类型(type):',
// scope: '选择一个更改的范围(scope) (可选):',
// used if allowCustomScopes is true
// customScope: 'Denote the SCOPE of this change:',
subject: '输入本次commit记录说明:\n',
// body: '长说明,使用"|"换行(可选):\n',
// breaking: '非兼容性说明 (可选):\n',
// footer: '关联关闭的issue,例如:#31, #34(可选):\n',
confirmCommit: '确定提交说明?',
},
skipQuestions: ['scope', 'body', 'breaking', 'footer'],
allowBreakingChanges: [
'fix',
'feat',
'update',
'refactor',
'perf',
'build',
'revert',
],
subjectLimit: 100,
};
五、使用git cz命令代替git commit
直接在项目的package.json文件中,在运行的脚本文件“scripts”中加入
"commit": "git add . && git cz"