使用Commitizen规范 git commit命令的提交信息

一、全局安装 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"

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值