博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Git Commit Hook
阅读量:3553 次
发布时间:2019-05-20

本文共 3226 字,大约阅读时间需要 10 分钟。

前言

刚好写Shell工程,需要规范代码提交,就简单记录下。╮(╯▽╰)╭

流程

安装插件

# 安装npm环境brew install npm# 安装插件npm install -g @commitlint/cli @commitlint/config-conventional
  • 如果对于commitlint有更多想要了解的,详见:
# 安装后,如果项目下面没有package.json[npm | cnpm] init -y

结果为:(提前将最终的配置结果贴出来,😁)

{  "name": "xxxx",  "version": "0.0.1",  "author": "notzonotdied",  "description": "xxxx",  "scripts": {  },  "license": "ISC",  "devDependencies": {    "@commitlint/cli": "^8.2.0",    "@commitlint/config-conventional": "^8.2.0",    "@commitlint/prompt": "^8.2.0",    "commitizen": "^4.0.3",    "conventional-changelog-cli": "^2.0.25",    "husky": "^4.0.0-beta.5"  },  "husky": {    "hooks": {      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"    }  },  "config": {    "commitizen": {      "path": "@commitlint/prompt"    }  },  "dependencies": {    "lint": "^0.7.0"  }}

配置commit规范

# 在项目根目录下执行如下指令echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js

commitlint.config.js

# 默认"module.exports = {extends: ['@commitlint/config-conventional']}"/** * add:         新增文件,新增功能 * update:      在原有的功能上新增 * revert: * chore:       构建过程或辅助工具的变动 * test:        增加测试 * refactor:    重构(即不是新增功能,也不是修改bug的代码变动) * style:       格式(不影响代码运行的变动) * docs:        文档(documentation) * fix:          修bug * feature: * */module.exports = {
extends: ['@commitlint/config-conventional'], rules: {
'type-enum': [2, 'always', [ "feature", "fix", "docs", "style", "refactor", "test", "chore", "revert", "update", "add" ]], 'subject-full-stop': [2, 'never', '.'], 'subject-case': [2, 'always', ['upper-case']] }}

上面我们就完成了commitlint的安装与提交规范的制定。检验commit message的最佳方式是结合git hook,。

  • 更多配置详见:

配置Git Hook:Husky

husky继承了Git下所有的钩子,在触发钩子的时候,husky可以阻止不合法的commit,push等等。注意使用husky之前,必须先将代码放到git 仓库中,否则本地没有.git文件,就没有地方去继承钩子了。

# 使用如下命令安装npm install husky --save-dev

安装成功后需要在项目下的package.json中配置:

# 下面是^4.0.0-beta.5版本的配置"husky": {  "hooks": {    "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"  }},

最后我们可以正常的git操作git add .,但是我们的git commit会被hook,只有符合规范的才会被提交。

生效

当我们配置完毕package.json后,就可以使用在根目录下执行yarn install即可。

{  "name": "xxxx",  "version": "0.0.1",  "author": "notzonotdied",  "description": "xxxx",  "scripts": {  },  "license": "ISC",  "devDependencies": {    "@commitlint/cli": "^8.2.0",    "@commitlint/config-conventional": "^8.2.0",    "@commitlint/prompt": "^8.2.0",    "commitizen": "^4.0.3",    "conventional-changelog-cli": "^2.0.25",    "husky": "^4.0.0-beta.5"  },  "husky": {    "hooks": {      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"    }  },  "config": {    "commitizen": {      "path": "@commitlint/prompt"    }  },  "dependencies": {    "lint": "^0.7.0"  }}
  • 执行yarn install
➜  xxx git:(master) yarn installyarn install v1.22.4warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.[1/4] 🔍  Resolving packages...[2/4] 🚚  Fetching packages...[3/4] 🔗  Linking dependencies...[4/4] 🔨  Building fresh packages...✨  Done in 5.09s.

执行完毕后会在项目根目录下生成package-lock.json

附录

  • 阮一峰的博客:
    • 推荐阅读这一篇了解npm的基本使用
  • Yarn安装:

转载地址:http://hqzrj.baihongyu.com/

你可能感兴趣的文章
Java问题百度/Google记录 2020-2-16
查看>>
【PADS9.5】9,对比ECO核心板,Router移动元件后布线消失,Router找不到自动布线策略文件丢失或损坏
查看>>
【STM32+w5500汇总】23,HTTP_Client 连接到ONENET上传了一段数据之后会断开,数据上传格式的设置
查看>>
【STM32+W5500+MQTT】24,所有功能都可以通过API函数的调用来实现;HTTP接入ONENET,API开发手册和打包函数,串口软件HTTP连接服务器上传数据,2018年12月28日
查看>>
【STM32+W5500+HTTPClient】25,路由器DHCP租赁IP时间为2h,NetBios可以很好的解决IP变化的问题,DNS,2018年12月25日
查看>>
【STM32+MQTT+ONENET】26,MQTT协议接入OneNET
查看>>
【STM32+W5500+MQTT+ONENET】27,MQTT协议接入OneNET实际编程操作 2018年12月27日
查看>>
【STM32Cube+FreeRTOS 】28,KEIL5的F12不起作用;***JLink Error: Can not read register x while CPU is running
查看>>
【STM32CubeMX+FreeRTOS 】29,prtinf卡死;4任务只运行了3个;W5500联网失败(堆栈不能太大或者太小)
查看>>
【STM32+FreeRTOS +W5500移植要点】30,RTOS中断;从TIM2,主TIM3;RTOS主要用在LCD中;RT-Thread;标志重定义问题 2019年01月22日
查看>>
【STM32+FPGA+FSMC】31,FSMC熟练掌握;KEIL5生成bin文件;SDRAM的使用;IAP检验码 2019年04月10日
查看>>
【IC1】【转 非常好】运算放大器使用的六个经验
查看>>
【IC-ADC 3】ADC的选型
查看>>
2019年03月18日 查看数据手册的注意点,极限参数、电气参数、推荐参数
查看>>
HiKey960/970用户手册;HiKey960 Development Board User Manual
查看>>
【书籍推荐】FPGA,xilinx
查看>>
N9-SQL注入(union注入)
查看>>
N10-sql注入(information_schema注入)
查看>>
N1-Kali虚拟机中SQLmap
查看>>
N11-sql注入(http头注入)
查看>>