git commit规范 Commitizen Commitlint

一.项目本地安装

1.npm install --save-dev commitizen

2.npx commitizen init cz-conventional-changelog --save-dev --save-exact

3.以后提交代码用 npx cz

4.Select the type of change that you're committing

Type 作用
feat 新增特性
fix 修复bug
docs 修改文档
style 代码格式修改(white-space, formatting)
refactor 代码重构
perf 改善性能
test 测试
build 变更项目构建或外部依赖(gulp, npm)
ci 更改持续集成软件的配置文件或package 中的scripts
chore 其他不修改src或测试文件的更改
revert 代码回退

5.What is the scope of this change (e.g. component or file name): (press enter to skip) 更改的范围是什么(例如组件或文件名):(按回车键跳过)

建议写

6.Write a short, imperative tense description of the change (max 88 chars):用简短的语句描述变更(最多88个字符)

必须写

7.Provide a longer description of the change: (press enter to skip)提供更长的变更描述:(按回车键跳过)

跳过

8.Are there any breaking changes? 有什么突破性的变化吗

9.Does this change affect any open issues? 这个变化是否影响到任何未解决的问题

二.这样配置完,如果主动用npx cz 是没问题了,可是此时用git commit 是可以绕过规则继续提交的,接下来要在 git commit 的时候做一下拦截判断

1.安装 commitlint
npm i @commitlint/cli @commitlint/config-conventional -D

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

3.如果没安装Husky,安装一下,如已安装则跳过此步
npx husky-init && npm install

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

三.前面把该装的都装了,现在验证吧

如果此时你随便 git commit -m '😄'就会报错了

此时你有两个选择

npx cz 按提示步骤弄
或者 git commit -m "fix: lint on commitmsg" 按标准写法来,把上面的标准type加进来,且冒号后面加一个空格

当然如果你觉得 npx cz 用着不习惯可以在 package.jsonscripts里面加一个"commit": "cz" 这样以后就用 npm run commit

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文链接 前言 在git的使用中,一种最佳实践是使用格式化的commit信息,这样方便自动化工具进行处理,可以快速...
    冯宇Ops阅读 8,666评论 2 34
  • 规范说明 git commit message即代码提交历史,错误的提交信息会影响代码的可维护性。在多人协作开发场...
    Bin_001阅读 902评论 0 3
  • 一. 代码规范 1.1. 集成editorconfig配置 EditorConfig 有助于为不同 IDE 编辑器...
    coderGuo666阅读 655评论 0 0
  • 项目搭建规范 一. 代码规范 1.1. 集成editorconfig配置 EditorConfig 有助于为不同 ...
    coderfly阅读 460评论 0 0
  • git的规范和相关科普知识 git commit 的规范要求(参考Angular团队) message格式如下: ...
    达文西_Huong阅读 802评论 0 0