背景
团队协作开发项目,git commit 可能也会存在参差不齐的情况,这时候可以用commitizen来规范代码提交。项目的变更记录,让人一目了然,引起强烈舒适。
开始
- 全局安装 Commitizen
npm install -g commitizen@4.2.4
- 安装 cz-customizable ,并在 package.json 中添加配置
npm i cz-customizable@6.3.0 -D
...
"config": {
"commitizen": {
"path": "node_modules/cz-customizable"
}
}
- 根目录下新增
.cz-config.js
module.exports = {
// 可选类型
types: [
{ value: 'feat', name: 'feat: 新功能' },
{ value: 'fix', name: 'fix: 修复' },
{ value: 'docs', name: 'docs: 文档变更' },
{ value: 'style', name: 'style: 代码格式' },
{ value: 'refactor', name: 'refactor: 代码重构' },
{ value: 'perf', name: 'perf: 性能优化' },
{ value: 'test', name: 'test: 增加测试' },
{ value: 'chore', name: 'chore: 构建过程或辅助工具的变动' },
{ value: 'revert', name: 'revert: 回退' },
{ value: 'build', name: 'build: 打包' }
],
// 步骤
messages: {
type: '请选择提交类型:',
customScope: '请输入修改范围(可选)',
subject: '请简要描述提交(必填)',
body: '请详细描述(可选)',
footer: '请输入要关闭的issue(可选)',
confirmCommit: '确认要使用以上信息提交吗?(y/n)'
},
// 跳过步骤
skipQuestions: ['body', 'footer'],
// 默认长度 72
subjectLimit: 72
}
- 使用
git cz代替git commit,大功告成啦🎉