定义
用于检查 Git 提交消息是否符合特定格式规则的工具。
Commitlint 可以和 Commitizen 搭配使用以实现高效和一致的提交消息管理。
Commitizen 提供了一个交互式界面,引导开发者填写提交消息的不同部分。
Commitlint 可以配置成在提交时自动运行,来确保提交消息遵循预定义的标准。
常见的标准格式为 Conventional Commits。如果以上两个工具一起使用,要确保使用的是同样的格式规则。
这篇文章介绍 Commitlint 的使用。
安装
npm install --save-dev @commitlint/{cli,config-conventional}
配置 Commitlint
在根目录创建 commitlint.config.js 文件
export default { extends: ['@commitlint/config-conventional'] }
集成 Commitlint 到 Git 钩子
手动在 .husky 目录下创建 commit-msg 文件
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx commitlint --edit $1
Type 提交类型
Type | 作用 |
---|---|
feat | 新增特性 (feature) |
fix | 修复 Bug(bug fix) |
docs | 修改文档 (documentation) |
style | 代码格式修改(white-space, formatting, missing semi colons, etc) |
refactor | 代码重构(refactor) |
perf | 改善性能(A code change that improves performance) |
test | 测试(when adding missing tests) |
build | 变更项目构建或外部依赖(例如 scopes: webpack、gulp、npm 等) |
ci | 更改持续集成软件的配置文件和 package 中的 scripts 命令,例如 scopes: Travis, Circle 等 |
chore | 变更构建流程或辅助工具(比如更改测试环境) |
revert | 代码回退 |
观摩一下 Vue 的 commit 消息写法: