而commitlint就是这样一种工具,通过结合husky一起使用,可以在开发者进行commit前就对Commit Message进行检查,只有符合规范,才能够进行commit。 上面我们提到过,git最常用的钩子函数有两个,一个是pre-commit,前面我们已经对这个阶段需要做的规范做了介绍,并且还使用了lint-staged工具。另外一个常用的钩子函数就是commit-m...
message 格式如下:<type>(<scope>): <subject> // 空一行 // 空一行 格式说明:分别对应 Commit message 的三个部分:Header,Body 和 FooterHeader Header 部分只有一行,包括三个字段:type(必需)、scope(可选)和 subject(必需) type: 用于说明 commit 的类型。一般有以下几种: feat: A new feature(新...
考虑到 git 的 hook 机制,可以基于commitlint配置,能继续用git commit命令;然而配置过程还是很繁琐,yml 和 package.json 的写法难以一下写对。 相比之下,gitlint则简单了许多:用 pip 而不是 nodejs 的 npm 安装;编写 .gitlint 的说明文档一看就懂。尝试配置如下。 配置 安装gitlint: pip install gitlint 找到...
"husky": {"hooks": {"commit-msg":"commitlint -E HUSKY_GIT_PARAMS""pre-commit":"lint-staged"//pre-commit,提交前的钩子} },"lint-staged": {//此处可以配置文件夹和文件类型的范围"src/**/*.{jsx,txs,ts,js,json,css,vue}": ["prettier --write",//先使用prettier进行格式化"eslint --fix...
对 commit message 格式进行校验:安装 @commitlint/cli、@commitlint/config-conventional npm install --save-dev @commitlint/config-conventional @commitlint/cli 使用 @commitlint/config-conventional 作为 lint 配置文件: echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint....
当然如果你使用 [commitlint](GitHub - conventional-changelog/commitlint: Lint commit messages) 规则定义了 scope-enum,会自动引入。 // .commitlintrc.js const fs = require('fs') const path = require('path') const packages = fs.readdirSync(path.resolve(__dirname, 'packages')) module.exports = ...
--hook是告诉 commitizen,这是在 git 钩子中运行的(直接命令行执行 cz 会生成 commit message 并提交 commit,如果通过 git 钩子触发,则是只负责生成 commit message,传给 git commit 命令) commitlint 类似eslint,commitlint则是对 commit message 进行规范校验。
git config commit.template[模板文件名]//这个命令只能设置当前分支的提交模板git config ——global commit.template[模板文件名]//这个命令能设置全局的提交模板,注意global前面是两杠 新建.gitmessage.txt(模板文件) 内容可以如下: 代码语言:javascript
git是现在市面上最流行的版本控制工具,书写良好的commit message能大大提高代码维护的效率。但是在日常开发中由于缺少对于commit message的约束,导致填写内容随意、质量参差不齐,可读性低亦难以维护。在项目中引入commit message规范已是迫在眉睫。
Git Commit-lint依赖于Node.js,因此首先需要安装Node.js环境。可以通过以下命令检查是否已经安装Node.js: node -v 如果未安装,可以访问Node.js官方网站下载安装包,或者使用包管理器(如apt或brew)安装Node.js: 使用apt安装(适用于Ubuntu/Debian): sudo apt-get update ...