Commitlint — Git 提交信息规范检查工具
基于 Conventional Commits 规范,通过 Husky Git Hooks 在提交时自动校验 commit message 格式,确保团队提交历史的可读性、可追溯性与自动化工具链的可集成性。
Commitlint 是基于 Conventional Commits 规范的 commit message 校验工具,通过 Husky 在提交时自动检查格式,确保团队提交历史可读、可追溯并支持自动化发布。
Commitlint — Git 提交信息规范检查工具
基于 Conventional Commits 规范,通过 Husky Git Hooks 在提交时自动校验 commit message 格式,确保团队提交历史的可读性、可追溯性与自动化工具链的可集成性。
技术简介说明
Commitlint 是由 conventional-changelog 组织维护的开源 commit message lint 工具。它通过解析提交信息、匹配预定义或自定义规则集,在开发者执行 git commit 的瞬间即时反馈,阻止不符合规范的提交进入版本历史。
Commitlint 的核心价值不只是"格式检查"——它是 Conventional Commits 规范的可执行层。通过结构化提交信息,团队可以获得:
- 自动化 CHANGELOG 生成:
feat:、fix:等类型自动归类 - 语义化版本推断:
BREAKING CHANGE触发大版本升级 - CI/CD 流水线集成:与
semantic-release联动实现全自动发布
Commitlint 采用插件化架构:核心引擎 (@commitlint/cli) 只负责解析和校验流程,实际规则来自可共享的 npm 配置包(如 @commitlint/config-conventional)。这种设计使规则集可以像 ESLint 配置一样跨项目复用、组合、覆盖。
2025-2026 年,Commitlint 持续活跃迭代。v20(2025 年 9 月)要求 Node.js 22+;v21(2026 年 5 月)进一步优化了配置加载和 TypeScript 支持。npm 包 commitlint 最新版为 v21.2.0(2026 年 6 月 30 日发布),@commitlint/cli 保持同步更新。配合 Husky v9+、cz-git 等现代工具,Commitlint 仍是前端工程化 commit 规范的事实标准。
基本信息
| 项目 | 详情 |
|---|---|
| 官网 | https://commitlint.js.org |
| GitHub | https://github.com/conventional-changelog/commitlint |
| License | MIT |
| 最新稳定版 | v21.2.0(2026-06-30) |
| Node.js 要求 | >= 22.12.0(v21 起) |
| Git 要求 | >= 2.13.2 |
| npm 包名 | @commitlint/cli(CLI)、commitlint(核心) |
| 主要维护者 | conventional-changelog 组织社区 |
| npm 周下载量 | 数百万(monorepo 工具链标准组件) |
| Monorepo 结构 | 基于 Lerna 管理,包含 @commitlint/* 约 30+ 子包 |
快速上手
安装
# 安装 CLI 和 Conventional Commits 推荐配置
pnpm add -D @commitlint/cli @commitlint/config-conventional
# 或使用 npm
npm install --save-dev @commitlint/cli @commitlint/config-conventional基础配置
创建 commitlint.config.js(或 commitlint.config.ts、.commitlintrc.json 等):
// commitlint.config.js
export default {
extends: ['@commitlint/config-conventional'],
rules: {
// 自定义规则示例
'type-enum': [
2,
'always',
[
'feat', // 新功能
'fix', // 修复 bug
'docs', // 文档变更
'style', // 代码格式(不影响逻辑)
'refactor', // 重构
'perf', // 性能优化
'test', // 测试相关
'build', // 构建系统或外部依赖
'ci', // CI 配置
'chore', // 其他杂务
'revert', // 回滚
],
],
'subject-case': [0], // 关闭 subject 大小写检查(适配中文)
'subject-max-length': [2, 'always', 100],
},
}最小示例:配合 Husky 使用
# 1. 安装 Husky 并初始化
pnpm add -D husky
npx husky init
# 2. 创建 commit-msg hook
echo "npx commitlint --edit \$1" > .husky/commit-msg
# 3. 测试
git commit -m "feat: 添加用户登录功能" # ✅ 通过
git commit -m "随便写点啥" # ❌ 报错,拒绝提交完整的 Husky 配置示例:
// package.json
{
"scripts": {
"prepare": "husky"
}
}# .husky/commit-msg
npx commitlint --edit "$1"核心概念与架构
Conventional Commits 规范
Commitlint 的默认行为基于 Conventional Commits 规范。该规范定义了提交信息的结构化格式:
<type>(<scope>): <subject>
<body>
<footer>
各部分说明:
| 部分 | 必填 | 说明 | 示例 |
|---|---|---|---|
type | ✅ | 提交类型,决定 CHANGELOG 分类和版本语义 | feat、fix、docs、style、refactor、perf、test、build、ci、chore、revert |
scope | ❌ | 影响范围,描述修改的模块或功能域 | auth、api、ui、deps |
subject | ✅ | 简短描述,不超过 100 字符 | 添加用户注册接口 |
body | ❌ | 详细说明,描述动机和变更对比 | 多行文本 |
footer | ❌ | 关联信息,如 BREAKING CHANGE、Issue 链接 | BREAKING CHANGE: 移除旧 API、Closes #123 |
示例:
feat(auth): 添加 OAuth2.0 第三方登录支持
集成 Google 和 GitHub OAuth 提供者,支持自动 token 刷新。
迁移现有 session 管理逻辑到新的 auth middleware。
Closes #456
fix(api): 修复分页查询返回重复数据的问题
使用 cursor-based 分页替代 offset-based,避免数据变更时的重复/遗漏。
BREAKING CHANGE: `GET /api/posts` 的 `page` 参数已弃用,改用 `cursor`。
Commitlint 架构
┌─────────────────────────────────────────────────────┐
│ Git Commit │
│ git commit -m "feat: 新功能" │
└──────────────────┬──────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ Husky (Git Hook 管理) │
│ .husky/commit-msg │
│ → npx commitlint --edit $1 │
└──────────────────┬──────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ @commitlint/cli (核心引擎) │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ Parser 解析器 │ │ Formatter │ │
│ │ (conventional)│ │ 格式化输出 │ │
│ └───────┬───────┘ └───────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────┐ │
│ │ Rules Engine (规则引擎) │ │
│ │ ← @commitlint/config-* │ │
│ │ ← 自定义 rules │ │
│ └───────────────────────────────┘ │
└──────────────────┬──────────────────────────────────┘
│
▼
┌─────────┴─────────┐
│ │
✅ 通过 → 完成提交 ❌ 失败 → 阻止提交并报错
核心特性
1. 可共享配置(Shareable Configs)
通过 npm 包发布和复用配置,团队可以在多个项目间共享统一的 commit 规范:
// 项目 commitlint.config.js
export default {
extends: ['@company/commitlint-config'], // 团队共享配置
}内置配置包:
@commitlint/config-conventional— Angular 风格(默认推荐)@commitlint/config-angular— Angular 官方规范@commitlint/config-lerna-scopes— Lerna monorepo scope 校验@commitlint/config-pnpm-scopes— pnpm workspace scope 校验
2. 插件化规则引擎
每条规则独立配置严重级别(0=关闭、1=警告、2=错误)和适用条件(always/never):
export default {
rules: {
'body-max-line-length': [2, 'always', 100],
'header-max-length': [1, 'always', 120], // 警告级别
'type-empty': [2, 'never'], // 禁止空 type
'subject-full-stop': [2, 'never', '.'], // 禁止句号结尾
},
}3. 条件性规则(When/Only)
支持按条件启用规则,如仅对特定 scope 检查:
export default {
rules: {
'scope-enum': [2, 'always', ['api', 'ui', 'core', 'deps']],
},
// 当 scope 为空时跳过 scope-enum 检查
defaultIgnores: true,
}4. 自定义 Parser
默认使用 conventional-commits-parser,可替换为自定义解析器:
export default {
parserPreset: './custom-parser.js',
}5. Prompt 模式(交互式)
@commitlint/prompt 提供基于 inquirer 的交互式提交引导:
pnpm add -D @commitlint/prompt// package.json
{
"config": {
"commitizen": {
"path": "@commitlint/prompt"
}
}
}6. CI 集成
在 CI 流水线中对 PR 的 commit messages 进行批量检查:
# 检查最近 N 次提交
npx commitlint --from HEAD~5 --to HEAD
# 或检查 PR 分支的所有提交
npx commitlint --from origin/main --to HEAD7. 多配置文件格式支持
支持多种配置文件格式,优先级从高到低:
commitlint.config.js(ESM)commitlint.config.ts(需 Node.js 22+ 或 tsx)commitlint.config.cjs.commitlintrc.json/.commitlintrc.js/.commitlintrc.ymlpackage.json中的commitlint字段
8. 异步规则与插件
支持异步规则函数,可用于查询外部系统(如 Jira Issue 是否存在):
export default {
rules: {
'jira-ticket': async (parsed) => {
const { footer } = parsed
const hasTicket = /JIRA-\d+/.test(footer || '')
return [hasTicket, '必须在 footer 中包含 Jira Issue 编号']
},
},
}9. TypeScript 原生支持
v21+ 对 TypeScript 配置文件提供开箱即用支持:
// commitlint.config.ts
import type { UserConfig } from '@commitlint/types'
const config: UserConfig = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'docs']],
},
}
export default config生态图
Commitlint 不是孤立工具,它是 commit 规范工具链 的校验层。完整生态:
┌──────────────────────────────────────────────────────────────┐
│ Commit 规范工具链生态 │
├──────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌──────────────────┐ │
│ │ Conventional │ │ Commitlint │ │
│ │ Commits 规范 │───→│ 规则检查/拦截 │ │
│ │ (格式标准) │ │ (执行层) │ │
│ └─────────────────┘ └────────┬─────────┘ │
│ │ │
│ │ 由以下触发 │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐│
│ │ Husky (Git Hooks 管理器) ││
│ │ .husky/commit-msg → npx commitlint --edit $1 ││
│ └─────────────────────────────────────────────────────────┘│
│ │
│ ┌─────────────────┐ ┌──────────────────┐ │
│ │ Commitizen │ │ cz-git │ │
│ │ (交互式 CLI 框架)│───→│ (现代适配器) │ │
│ │ cz 命令引导提交 │ │ 支持 OpenAI 辅助 │ │
│ └─────────────────┘ └──────────────────┘ │
│ │
│ ┌─────────────────┐ ┌──────────────────┐ │
│ │ lint-staged │ │ semantic-release │ │
│ │ (暂存区文件过滤) │ │ (自动化发布) │ │
│ │ 配合 pre-commit │ │ 基于 commit 类型 │ │
│ └─────────────────┘ │ 决定版本号和 │ │
│ │ CHANGELOG │ │
│ └──────────────────┘ │
│ │
│ ┌─────────────────┐ ┌──────────────────┐ │
│ │ Changesets │ │ standard-version │ │
│ │ (Monorepo 变更) │ │ (版本/CHANGELOG) │ │
│ │ 更细粒度的变更管理│ │ 已被 changesets │ │
│ └─────────────────┘ │ 逐步替代 │ │
│ └──────────────────┘ │
└──────────────────────────────────────────────────────────────┘
关键工具角色
| 工具 | 角色 | 与 Commitlint 关系 |
|---|---|---|
| Conventional Commits | 格式规范标准 | Commitlint 的规则来源 |
| Husky | Git Hooks 管理 | 在 commit-msg hook 中触发 Commitlint |
| Commitizen | 交互式提交 CLI | 辅助生成符合规范的 commit message |
| cz-git | Commitizen 适配器 | 现代交互式提交 UI,支持 OpenAI |
| lint-staged | 暂存区文件过滤器 | 常与 Commitlint 并行配置在 pre-commit |
| semantic-release | 自动发布工具 | 消费 Commitlint 保证的结构化提交 |
| Changesets | Monorepo 变更管理 | 补充 Commitlint 覆盖不到的包级变更 |
适用场景
1. 团队协作项目
多人协作的代码仓库需要统一的 commit 风格。Commitlint 通过 Husky 在每次提交时强制执行规范,防止"格式混乱"的提交进入主分支。适用于:
- 企业级前端项目
- 开源社区项目
- 外包项目(多团队交付)
2. 自动化 CHANGELOG 生成
配合 conventional-changelog-cli 或 semantic-release,基于 commit 类型自动生成 CHANGELOG:
# 安装
pnpm add -D conventional-changelog-cli
# 生成 CHANGELOG
npx conventional-changelog -p angular -i CHANGELOG.md -s3. 语义化自动发布(semantic-release)
结构化提交信息驱动版本号和发布流程:
pnpm add -D semantic-release# .github/workflows/release.yml
name: Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npx semantic-release4. Monorepo 多包管理
在 pnpm workspace / Turborepo / Nx 等 monorepo 中,使用 scope 校验确保提交信息关联到正确的包:
// commitlint.config.js
export default {
extends: ['@commitlint/config-conventional', '@commitlint/config-pnpm-scopes'],
}5. CI/CD 质量门禁
在 CI 中对 Pull Request 的所有 commit 进行批量校验,阻止不合规的提交合并:
# GitHub Actions 示例
- name: Lint commit messages
run: npx commitlint --from origin/main --to HEAD --verbose6. 合规审计与追溯
对于有合规要求的行业(金融、医疗、政务),结构化 commit 信息提供完整的变更追溯链,每条提交都可关联到 Issue、MR、负责人。
7. 新人 Onboarding
配合 cz-git 等交互式工具,新成员无需记忆 commit 格式,通过交互式引导即可完成规范提交,降低团队规范的学习成本。
开发与工程化
项目目录结构(典型集成)
project/
├── commitlint.config.ts # Commitlint 配置
├── .commitlintrc.json # 或 JSON 格式配置
├── .husky/
│ ├── commit-msg # commit-msg hook
│ └── pre-commit # pre-commit hook(lint-staged)
├── package.json
└── ...
package.json 集成配置
{
"scripts": {
"prepare": "husky",
"commit": "cz",
"lint:commits": "commitlint --from HEAD~10 --to HEAD"
},
"devDependencies": {
"@commitlint/cli": "^21.2.0",
"@commitlint/config-conventional": "^21.0.2",
"commitizen": "^4.3.0",
"cz-git": "^1.11.0",
"husky": "^9.1.0",
"lint-staged": "^15.2.0"
},
"config": {
"commitizen": {
"path": "cz-git"
}
},
"lint-staged": {
"*.{ts,tsx,vue}": ["eslint --fix", "prettier --write"]
}
}cz-git 配置(中文友好)
// commitlint.config.js
import { defineConfig } from 'cz-git'
export default {
extends: ['@commitlint/config-conventional'],
rules: {
'subject-case': [0],
'subject-full-stop': [0],
},
prompt: {
alias: { fd: 'docs: fix typos' },
messages: {
type: '选择你要提交的类型:',
scope: '选择一个 scope(可选):',
subject: '填写简短描述:\n',
body: '填写详细描述(可选,使用 "|" 换行):\n',
footerPrefix: '填写关联 Issue(可选):\n',
confirmCommit: '确认提交吗?',
},
types: [
{ value: 'feat', name: 'feat: 新功能' },
{ value: 'fix', name: 'fix: 修复 bug' },
{ value: 'docs', name: 'docs: 文档变更' },
{ value: 'style', name: 'style: 代码格式' },
{ value: 'refactor', name: 'refactor: 重构' },
{ value: 'perf', name: 'perf: 性能优化' },
{ value: 'test', name: 'test: 测试' },
{ value: 'build', name: 'build: 构建' },
{ value: 'ci', name: 'ci: CI 配置' },
{ value: 'chore', name: 'chore: 杂务' },
{ value: 'revert', name: 'revert: 回滚' },
],
useEmoji: false,
emojiAlign: 'center',
themeColorCode: '',
scopes: [],
allowCustomScopes: true,
allowEmptyScopes: true,
upperCaseSubject: false,
breaklineNumber: 100,
breaklineChar: '|',
skipQuestions: [],
issuePrefixes: [{ value: 'closed', name: 'closed: ISSUES 已完成' }],
customIssuePrefixAlign: 'left',
emptyIssuePrefixAlias: 'skip',
customIssuePrefixAlias: 'custom',
allowCustomIssuePrefix: true,
allowEmptyIssuePrefix: true,
confirmCommit: 'warn',
},
}自定义共享配置包
创建可发布的 npm 配置包供团队复用:
commitlint-config-team/
├── index.js
├── package.json
└── README.md
// commitlint-config-team/index.js
module.exports = {
rules: {
'type-enum': [2, 'always', [
'feat', 'fix', 'docs', 'style', 'refactor',
'perf', 'test', 'build', 'ci', 'chore', 'revert',
]],
'subject-case': [0],
'subject-full-stop': [2, 'never', '。'], // 中文句号
'subject-max-length': [2, 'always', 100],
'body-max-line-length': [1, 'always', 200],
},
}// package.json
{
"name": "commitlint-config-team",
"version": "1.0.0",
"main": "index.js"
}项目中使用:
// commitlint.config.js
export default {
extends: ['team'], // 自动解析为 commitlint-config-team
}性能与安全
性能
- 检查耗时:单次 commit message 检查通常 < 50ms,不会明显影响提交体验
- 冷启动:首次执行
npx commitlint需要加载 Node.js 和依赖,约 200-500ms - 优化方式:通过 Husky 本地 hook 运行时避免远程调用;CI 中可通过
--from/--to限定检查范围 - 并发友好:Commitlint 是无状态工具,天然支持并行执行
安全
- 依赖链风险:Commitlint 依赖
conventional-commits-parser等包,需定期通过pnpm audit检查 - 配置注入:自定义规则若引用外部数据源(如 API),需注意输入验证
- Hook 权限:Husky 的 hook 文件存放在
.husky/目录,需确保其不被恶意修改 - 供应链安全:使用共享配置包时,应审计
@scope/commitlint-config-*包的来源和内容
技术对比
| 特性 | Commitlint | gitlint | commitlint(Rust 重写版) | 手写 shell 脚本 |
|---|---|---|---|---|
| 语言 | Node.js | Python | Rust | Bash/sh |
| Conventional Commits | ✅ 原生支持 | ✅ 插件支持 | ✅ | ❌ 需自行实现 |
| 可共享配置 | ✅ npm 包 | ❌ | ❌ | ❌ |
| Husky 集成 | ✅ 官方文档 | ⚠️ 需手动 | ⚠️ 需手动 | ✅ |
| 自定义规则 | ✅ 插件化 | ✅ | ❌ | ⚠️ 有限 |
| CI 集成 | ✅ | ✅ | ✅ | ✅ |
| 社区生态 | 丰富(conventional-changelog 组织) | 中等 | 早期 | 无 |
| 执行速度 | 中等(~50ms) | 中等 | 极快(~5ms) | 极快 |
| Node.js 依赖 | 必须 | 不需要 | 不需要 | 不需要 |
| 维护活跃度 | 活跃(2026 持续更新) | 活跃 | 早期阶段 | 自维护 |
选型建议:
- Node.js / 前端项目 → Commitlint(生态最完整)
- Python 后端项目 → gitlint
- 对性能极度敏感 / 无 Node.js → Rust 重写版或 pre-commit 集成
- 极简需求 → 手写 shell 脚本即可
最佳实践
中文 Commit 规范适配
// commitlint.config.js
export default {
extends: ['@commitlint/config-conventional'],
rules: {
// 关闭英文大小写检查
'subject-case': [0],
// 关闭句号结尾检查(中文使用全角句号)
'subject-full-stop': [2, 'never', '。'],
// 允许中文标点
'header-full-stop': [0],
// type 必须存在
'type-empty': [2, 'never'],
// subject 必须存在
'subject-empty': [2, 'never'],
// subject 最大长度
'subject-max-length': [2, 'always', 100],
// body 每行最大长度
'body-max-line-length': [1, 'always', 200],
},
}中文 Type 与 Scope 约定
feat(auth): 添加微信登录支持
fix(api): 修复分页查询返回重复数据
docs(readme): 更新安装说明
style(format): 统一代码缩进为 2 空格
refactor(user): 重构用户信息缓存逻辑
perf(render): 优化长列表渲染性能
test(auth): 补充登录模块单元测试
build(deps): 升级 vue 到 3.5.0
ci(github): 添加自动化发布流程
chore: 清理废弃的配置文件
revert: 回滚 feat(auth): 添加微信登录支持
Conventional Commits 中文增强版
项目可在 type 基础上扩展中文场景(需同步更新 type-enum 规则):
{
types: [
{ value: 'feat', name: 'feat: ✨ 新功能' },
{ value: 'fix', name: 'fix: 🐛 修复 bug' },
{ value: 'docs', name: 'docs: 📝 文档变更' },
{ value: 'style', name: 'style: 💄 代码格式(不影响逻辑)' },
{ value: 'refactor', name: 'refactor: ♻️ 重构(非新增功能/修复)' },
{ value: 'perf', name: 'perf: ⚡️ 性能优化' },
{ value: 'test', name: 'test: ✅ 测试相关' },
{ value: 'build', name: 'build: 📦️ 构建系统或依赖变更' },
{ value: 'ci', name: 'ci: 👷 CI/CD 配置变更' },
{ value: 'chore', name: 'chore: 🔨 其他杂务' },
{ value: 'revert', name: 'revert: ⏪️ 回滚提交' },
// 扩展类型
{ value: 'wip', name: 'wip: 🚧 进行中的工作' },
{ value: 'i18n', name: 'i18n: 🌍 国际化' },
{ value: 'a11y', name: 'a11y: ♿ 无障碍' },
],
}Monorepo Scope 校验
// commitlint.config.js(pnpm workspace 项目)
export default {
extends: [
'@commitlint/config-conventional',
'@commitlint/config-pnpm-scopes',
],
}自动从 pnpm-workspace.yaml 读取包名作为合法 scope,防止提交信息关联到不存在的包。
避免常见陷阱
-
不要在已有大量不规范提交的项目上直接启用
# 解决方案:对历史提交不做追溯,只检查新提交 # Husky hook 中只拦截新 commit -
不要忽略
--edit参数# ❌ 错误 — 会检查整个 commit 文件 npx commitlint # ✅ 正确 — 只检查本次 commit message npx commitlint --edit "$1" -
不要合并冲突时跳过检查
# 如果确实需要跳过(如合并),使用环境变量 HUSKY=0 git commit -m "merge: ..." -
配置文件格式与 Node.js 版本兼容
// Node.js 24+ 默认 ESM,.js 配置文件需要使用 export default export default { ... } // 或使用 .cjs 扩展名保持 CommonJS module.exports = { ... }
技术局限与边界
已知局限
-
只检查 commit message,不检查代码内容 Commitlint 只关心提交信息的格式,不验证代码质量、测试覆盖率或变更范围。需配合 ESLint、lint-staged 等工具使用。
-
无法保证语义正确性 开发者可以写
feat: 修复 bug(type 与实际内容不符),Commitlint 只能检查格式,无法验证语义。需 Code Review 补充。 -
对历史提交无约束 Commitlint 只检查新提交。迁移旧项目时,历史不规范提交无法自动修复。
-
Node.js 依赖 必须安装 Node.js 运行时。非 Node.js 项目(纯 Python/Go/Rust)引入 Commitlint 会带来不必要的运行时依赖。
-
规则引擎无法覆盖复杂业务逻辑 如需基于变更文件内容决定 commit 类型(如"修改了
auth/目录必须用authscope"),Commitlint 无法原生支持,需自定义 parser 或外部脚本。 -
与某些 Git GUI 工具的兼容性 部分 Git GUI(如旧版 SourceTree)可能不正确触发
commit-msghook,导致校验被绕过。
明确边界
| Commitlint 做 | Commitlint 不做 |
|---|---|
| 校验 commit message 格式 | 校验代码质量 |
| 拦截不规范提交 | 自动修复 commit message |
| 提供结构化提交信息 | 推断变更语义正确性 |
| 配合 semantic-release 自动发布 | 替代 Code Review |
| 配合 cz-git 引导输入 | 替代开发者记忆规范 |
学习资源
官方资源
- Commitlint 官网 — 文档入口
- GitHub 仓库 — 源码和 Issue
- Conventional Commits 规范 — 格式标准
- Commitlint 配置参考 — 完整配置 API
中文教程
- Git 提交信息规范(Commitlint + commitizen + cz-git) — 博客园完整教程
- 把 Git 提交变成"可执行规范" — 掘金 2026 年文章
- Commitizen + Husky + Commitlint 实现校验 — 掘金教程
- cz-git 官方文档 — 中文适配器文档
英文教程
- How to Set Up Commitlint to Enforce Clean Git Commit Messages — Medium 2025
- Apply Conventional Commit Style with Commitlint — 2026 年更新
- How to Configure Conventional Commits — OneUptime 2026
视频
- Never Write a Bad Commit Again! Commitlint + Commitizen Combo — YouTube 2025
- How to Setup Commitlint & Husky in Your Project — YouTube 2025
2026 年现状
版本进展
- v21(2026 年 5 月发布):要求 Node.js 22+,优化 TypeScript 配置加载,Node 24+ 下配置文件需使用 ESM 格式
- v20(2025 年 9 月发布):引入 Node.js 22 支持,废弃 Node.js 18
- 持续活跃:2026 年 6 月 30 日发布 v21.2.0,保持每月至少一次更新的节奏
生态变化
-
cz-git 成为主流适配器 相比传统的
cz-conventional-changelog,cz-git 提供更好的交互体验、TypeScript 支持、以及 OpenAI 辅助生成 commit message 的能力,2025-2026 年成为中文社区首选。 -
Husky v9+ 简化配置 Husky 从 v9 开始使用
.husky/目录直接存放 hook 脚本,不再需要husky install命令,配置更简洁。 -
与 Changesets 的互补关系明确 Commitlint 负责 commit message 格式,Changesets 负责包级别的变更追踪和版本管理。两者在 monorepo 中常同时使用。
-
Rust 重写版的探索 社区出现了无 Node.js 依赖的 Commitlint Rust 重写版(2025 年讨论),性能提升约 10 倍。但官方版本仍保持 Node.js 路线。
-
AI 辅助提交成为趋势 cz-git 等工具已集成 AI 生成 commit message 的能力。Commitlint 作为校验层,确保 AI 生成的提交也符合规范。
是否值得新项目采用?
强烈推荐。Commitlint 仍是 2026 年 commit 规范的事实标准工具。配合 Husky + cz-git + semantic-release,可以构建完整的"提交即文档"工作流。对于:
- 新项目:从第一天起就配置,零迁移成本
- 存量项目:渐进式引入,对新 commit 执行检查
- Monorepo:结合
@commitlint/config-pnpm-scopes做 scope 约束 - 多语言项目:如主仓库为 Node.js,统一使用 Commitlint;纯非 Node 项目可考虑 gitlint 或 Rust 方案