commitizen + husky规范

husky + commitizen 规范git commit提交

安装husky

  • 官网 https://typicode.github.io/husky/#/?id=yarn-2

  • npm install husky --save-dev  # 安装
    npx husky install 
    npm set-script prepare "husky install"
    

创建钩子

  • pre-commit 勾子

    • npx husky add .husky/pre-commit "npm test"
      

以上, 成功实现在git commit 之前进行 test

  • commit-msg勾子

    • npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
      

这个时候,这个勾子会报错,继续接下来操作

规范提交

安装插件

  • 用git cz 命令来创建一个规范的git commit -m
npm i -D commitizen cz-conventional-changelog # 局部安装

配置package.json

"config": {
  "commitizen": {
    "path": "./node_modules/cz-conventional-changelog"
  }
}

配合commitlint校验

  • 安装插件
npm i -D @commitlint/config-conventional @commitlint/cli
  • 在项目根目录下创建配置文件 commitlint.config.js

    • 'use strict';
      module.exports = {
        extents: [
          '@commitlint/config-conventional',
        ],
        rules: {
          'body-leading-blank': [ 1, 'always' ],
          'footer-leading-blank': [ 1, 'always' ],
          'header-max-length': [ 2, 'always', 72 ],
          'scope-case': [ 2, 'always', 'lower-case' ],
          'subject-case': [
            2,
            'never',
            [ 'sentence-case', 'start-case', 'pascal-case', 'upper-case' ],
          ],
          'subject-empty': [ 2, 'never' ],
          'subject-full-stop': [ 2, 'never', '.' ],
          'type-case': [ 2, 'always', 'lower-case' ],
          'type-empty': [ 2, 'never' ],
          'type-enum': [
            2,
            'always',
            [
              'build',
              'chore',
              'ci',
              'docs',
              'feat',
              'fix',
              'improvement',
              'perf',
              'refactor',
              'revert',
              'style',
              'test',
            ],
          ],
        },
      };
      
      

使用

git cz 
  • refactor 简单代码的重构
  • revert 撤销
  • chore 不知道怎么分类,选这个
  • are there any breaking changes? 有没有不兼容的特性?

在这里插入图片描述

  • 这个时候,随便git commit -m ‘hello’ 就会不允许提交, 必须符合规范, 使用git cz 就会符合规范。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值