# 约定式提交

**约定式提交**（Conventional Commits）是一套面向 Git 提交信息的轻量级规范，它把每条提交信息组织为 `类型[可选范围]: 描述` 的结构，并可在其后附加可选的正文与可选的脚注，从而让提交信息同时具备人类可读与机器可读的含义。该规范以 1.0.0 版本发布于 conventionalcommits.org，将提交类别映射到语义化版本（SemVer）之上，使自动化工具能够从提交历史中推导出版本号、变更日志与发布说明。<sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup>

| 关键事实 | 详情 |
|---|---|
| 当前版本 | 1.0.0，托管于 conventionalcommits.org<sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup> |
| 消息结构 | `<类型>[可选范围]: <描述>`，其后为可选正文与可选脚注<sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup> |
| 规范定义的类型 | 仅有 `fix`（SemVer 补丁）与 `feat`（SemVer 次版本）；`BREAKING CHANGE:` 脚注或在类型/范围后加 `!` 表示主版本变更<sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup><sup> • </sup><sup>[2](https://github.com/khasky/awesome-commit-conventions)</sup> |
| 常见扩展类型 | build、chore、ci、docs、feat、fix、perf、refactor、revert、style、test，依据基于 Angular 约定的 commitlint conventional 预设<sup>[3](https://github.com/conventional-changelog/commitlint)</sup> |
| 起源 | 2017 年由 Yargs/npm 生态的本杰明·E·科创建，是对 Angular 提交约定的泛化<sup>[2](https://github.com/khasky/awesome-commit-conventions)</sup> |
| 主要强制执行工具 | commitlint，按约定格式检查提交信息，被视为稳定<sup>[3](https://github.com/conventional-changelog/commitlint)</sup> |
| 发布自动化 | semantic-release 读取约定式提交信息，以确定下一个 SemVer 版本、生成变更日志并发布<sup>[4](https://semantic-release.gitbook.io/semantic-release)</sup> |

## 消息结构

一条约定式提交消息由以空行分隔的三部分组成：头部、可选正文与可选脚注。头部承载类型、括号中的可选范围以及描述，例如 `feat(parser): add ability to parse arrays`。<sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup> 范围提供额外的上下文信息，例如受影响的子系统。<sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup> commitlint 支持在一条消息中使用多个范围，以 `/`、`\` 或 `,` 等分隔符隔开。<sup>[5](https://commitlint.js.org/concepts/commit-conventions.html)</sup>

规范定义了三个元素的语义：<sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup>

1. `fix`：修补代码库中的缺陷，对应语义化版本中的补丁。
2. `feat`：引入新功能，对应次版本。
3. `BREAKING CHANGE`：带有 `BREAKING CHANGE:` 脚注的提交，或在类型/范围后追加 `!` 的提交，引入破坏性 API 变更，对应主版本。破坏性变更可以是任意类型提交的一部分。

`fix` 与 `feat` 之外的类型是允许的，但除非包含破坏性变更，否则不带有隐含的 SemVer 效果。`BREAKING CHANGE:` 之外的脚注遵循类似 Git 尾注（trailer）格式的约定。<sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup>

## 与 Angular 约定的关系

`feat`、`fix`、`docs` 等类型词汇源自 [AngularJS](https://www.edgepedia.org/zh/angularjs) 贡献指南，Angular 项目的提交信息准则至今仍是规范在类型定义方面所指的参考。<sup>[2](https://github.com/khasky/awesome-commit-conventions)</sup><sup> • </sup><sup>[1](https://www.conventionalcommits.org/en/v1.0.0/)</sup> Angular 约定比约定式提交更严格：它要求除 `docs` 类型外的所有提交都必须有至少 20 个字符的正文，将范围固定为一组包名，并要求摘要使用祈使句现在时且末尾不加句号。<sup>[6](https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md)</sup> 约定式提交将 Angular 格式泛化为一套与工具无关、任何项目都可采用的标准，而 Angular 仍是其原始实现。<sup>[7](https://geekworkbench.com/blog/technical/commit-message-conventions)</sup>

基于 Angular 约定的 `@commitlint/config-conventional` 预设识别 build、chore、ci、docs、feat、fix、perf、refactor、revert、style 与 test 这些类型，项目可以在自己的配置中修改这一集合。<sup>[3](https://github.com/conventional-changelog/commitlint)</sup>

## 工具生态

**commitlint** 是主要的检查工具。它检查提交信息是否符合约定格式，可在提交时本地运行（通常借助 husky 之类的 Git 钩子）或在 CI 中运行，并加载以 devDependencies 方式安装的共享配置，例如 `@commitlint/config-conventional`。<sup>[3](https://github.com/conventional-changelog/commitlint)</sup><sup> • </sup><sup>[8](https://commitlint.js.org/guides/getting-started)</sup>

**conventional-changelog** 从 Git 元数据生成 `CHANGELOG.md`：它解析约定式历史，将提交归入“功能”“缺陷修复”等小节，并把每条记录链接回其提交与发布。配套工具 `conventional-recommended-bump` 读取自上一个标签以来的提交，推荐下一次发布是主版本、次版本还是补丁。<sup>[9](https://conventional-changelog.js.org/getting-started/)</sup>

**semantic-release** 将这一闭环补全为全自动的发布流水线。它利用提交信息判断变更对使用者的影响，自动确定下一个语义化版本号，生成变更日志，并在发布分支上每次成功构建后从 CI 发布。在其默认配置下，`fix` 提交产生补丁发布，`feat` 提交产生次版本发布，带 `BREAKING CHANGE:` 脚注的提交产生主版本发布。<sup>[4](https://semantic-release.gitbook.io/semantic-release)</sup> commitlint 与 semantic-release 可以共用同一个 `conventional-changelog-conventionalcommits` 预设，使检查时解析的提交与 semantic-release 用于版本管理和变更日志生成的提交保持一致。<sup>[10](https://commitlint.js.org/reference/configuration.html)</sup>

## 采用与实践

该规范在 conventionalcommits.org 的仓库在 GitHub 上约有 9.3k 星标，网站结构仿照 semver.org 搭建。<sup>[11](https://github.com/conventional-commits/conventionalcommits.org)</sup> 严格使用约定式提交的项目包括该约定的发源者 Angular，以及采用自动化发布的 Vue；其他大型项目则使用自己的体系，例如 React 的方括号标签区域标注、Kubernetes 的自由式祈使风格，以及 [Linux 内核](https://www.edgepedia.org/zh/linux-kernel)强制要求 `Signed-off-by:` 行的 `subsystem: description` 格式。<sup>[2](https://github.com/khasky/awesome-commit-conventions)</sup>

若干常被归到该规范名下的习惯其实并不属于它。类型与描述使用小写是 Angular 的风格而非规范要求；规范将提交各部分视为大小写不敏感，唯独 `BREAKING CHANGE` 必须大写。主题 50 字符、正文 72 字符的行长准则来自 Git 与内核实践，而非约定式提交。<sup>[2](https://github.com/khasky/awesome-commit-conventions)</sup>

## 已知局限

规范并未提供一份确定的类型定义清单；它让使用者参考 Angular 项目的定义，而一项对约定式提交议题与 Stack Overflow 问题的研究发现，这些定义过于宽泛且相互重叠。在已归类的问题中，关于该用哪种类型的困惑占 57.7%，包括不确定 `feat` 面向的是用户导向功能还是开发者导向功能，以及 `refactor` 与 `style`、`perf` 如何重叠。规范社区内部关于引入确定类型清单的讨论始于 2020 年 7 月，截至该研究时尚未取得显著进展。<sup>[12](https://0x404.github.io/assets/pdf/conventional_commit.pdf)</sup>

更广泛的背景同样重要：一项对来自五个高度活跃开源项目的近 1600 条提交信息的多方法研究发现，平均约 44% 的信息有改进空间，这也是团队将该格式与检查工具搭配使用、而非仅依赖约定的原因之一。<sup>[13](https://arxiv.org/abs/2202.02974)</sup>

## References

1. [Conventional Commits 1.0.0, conventionalcommits.org](https://www.conventionalcommits.org/en/v1.0.0/)
2. [Awesome Commit Conventions, khasky on GitHub](https://github.com/khasky/awesome-commit-conventions)
3. [commitlint: Lint commit messages, conventional-changelog on GitHub](https://github.com/conventional-changelog/commitlint)
4. [semantic-release documentation](https://semantic-release.gitbook.io/semantic-release)
5. [Concept: Commit conventions, commitlint](https://commitlint.js.org/concepts/commit-conventions.html)
6. [Angular commit message guidelines, angular/angular on GitHub](https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md)
7. [Commit Message Conventions: Conventional Commits, Angular Style, and Semantic Commits, Geek Workbench](https://geekworkbench.com/blog/technical/commit-message-conventions)
8. [Getting started, commitlint](https://commitlint.js.org/guides/getting-started)
9. [Introduction, Conventional Changelog](https://conventional-changelog.js.org/getting-started/)
10. [Configuration, commitlint](https://commitlint.js.org/reference/configuration.html)
11. [conventionalcommits.org repository, conventional-commits on GitHub](https://github.com/conventional-commits/conventionalcommits.org)
12. [A First Look at Conventional Commits Classification](https://0x404.github.io/assets/pdf/conventional_commit.pdf)
13. [What Makes a Good Commit Message?, arXiv:2202.02974](https://arxiv.org/abs/2202.02974)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Version control and collaboration platforms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/conventional-commits

English original: https://www.edgepedia.org/conventional-commits
