Git Commit强制规范(commitlint+husky)
作者:互联网
从我的notion文档迁移到的博客园:[https://www.notion.so/Git-Commit-commitlint-husky-9cc381b35484437ca32f474cda40dc24)
Git Commit强制规范(commitlint+husky)
一、缘起
- 规范前
- 规范后
二、工具介绍
1、commitlint
commitlint 是当前使用最为广泛的 git commit 校验约束工具之一,
commitlint helps your team adhering to a commit convention. By supporting npm-installed configurations it makes sharing of commit conventions easy.
(1)安装
npm install -g @commitlint/cli @commitlint/config-conventional
config-conventional是社区整理的常用的Commit规范,见如下
https://www.npmjs.com/package/@commitlint/config-conventional
(2)配置
生成commitlint.config.js配置文件,命令如下:
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
-
默认采用config-conventional:
module.exports = {extends: ['@commitlint/config-conventional']};
-
可自定义配置:
配置规则见 https://commitlint.js.org/#/reference-configuration
module.exports = { extends: ['@commitlint/config-conventional'], rules: { 'type-enum': [2, 'always', [ "feat", "upd", "del", "fix", "refactor", "test", "perf", "docs", "style", "revert" ]], 'subject-full-stop': [0, 'never'], 'subject-case': [0, 'never'] } };
2、husky
Husky can prevent bad git commit, git push and more
标签:git,Commit,Git,commit,husky,config,commitlint 来源: https://www.cnblogs.com/hepc/p/13917489.html