• git hook


    git commit-msg
    可以用来规范标准格式,并且可以按需要指定是否要拒绝本次提交

    git pre-commit
    会在提交前被调用,并且可以按需要指定是否要拒绝本次提交

    使用husky + commitlint 检查提交代码
    commitlint:用于检查提交信息
    husky 是gits hooks工具

    commitlint
    1.安装依赖
    npm install --save-dev @commitlint/config-conventional@12.1.4 @commitlint/cli@12.1.4

    2.创建 commitlint.config.js文件

    echo "module.exports = {extends:['@commitlint/config-conventional']}" > commitlint.config.js
    
    • 1

    3.打开 commitlint.config.js 增加配置项

    module.exports = {
      // 继承的规则
      extends: ['@commitlint/config-conventional'],
      // 定义规则类型
      rules: {
        // type 类型定义,表示 git 提交的 type 必须在以下类型范围内
        'type-enum': [
          2,
          'always',
          [
            'feat', // 新功能 feature
            'fix', // 修复 bug
            'docs', // 文档注释
            'style', // 代码格式(不影响代码运行的变动)
            'refactor', // 重构(既不增加新功能,也不是修复bug)
            'perf', // 性能优化
            'test', // 增加测试
            'chore', // 构建过程或辅助工具的变动
            'revert', // 回退
            'build' // 打包
          ]
        ],
        // subject 大小写不做校验
        'subject-case': [0]
      }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    husky
    1.安装 依赖
    npm install husky@7.0.1 --save-dev

    2启动hooks,生成 .husky文件
    npx husky install

    3.在package.json中生成prepare指令
    npm set-script prepare “husky install”

    4.执行 prepare指令
    npm run prepare

    5.添加 commitlint的hook到husky中,并指令在 commit-msg的hooks下执行 npx --no-install commitlint --edit “$1”

    npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1" '
    
    
    • 1
    • 2
  • 相关阅读:
    MySQL高级篇知识点——主从复制
    QT 自定义抽屉式窗口,上层覆盖下层界面,下层布局不改变
    栈 之 如何实现一个栈
    Java开发的核心模式 - MVC
    6-4代码块
    内网渗透之Socks代理简介
    PMP备考大全:经典题库(8月第1、2周)
    家里蹲了七个月的大学生活是怎么度过的?
    Spring Framework 6.1 正式 GA
    Linux开发板配置静态IP
  • 原文地址:https://blog.csdn.net/qq_35285627/article/details/126257329