Git 提交信息样式指南

该指南是各种项目中所需遵守的通用指南。如果和所在组织或公司的规定不同,则遵守组织或公司的专有规定。

信息结构

提交信息由 3 个不同的部分构成:

  • 标题(必需)
    • 类型
    • 主题
  • 正文(可选)
  • 注释(可选)

三部分之间用空行分隔。

标题的两部分在一行内,要使用英文冒号(:)分隔,即:类型:主题

有固定的分类格式,用来标明修改的种类:

  • feat: 新功能
  • fix:错误修复
  • docs:文档修改
  • style:格式、分号缺失等,代码无变动
  • refactor:生产代码重构
  • test:测试添加、测试重构等,生产代码无变动
  • chore:构建任务更新、程序包管理器配置等,生产代码无变动

尽量使用简短的语句描述当前提交的作为。 如果使用英文要注意:

  • 主题不超过 50 个字符
  • 首字母大写
  • 句末无句号
  • 使用祈使语气陈述,如:使用 change 而非 changed 或 changes

并不是所有的提交信息都复杂到需要正文,因此这是可选内容,仅在提交信息需要一定的解释和语境时使用。 需要注意的要点有:

  • 用于解释提交任务的内容和原因,而不是方法。
  • 使用祈使语气陈述
  • 如果需要,可加入提交造成的更改的前后对比描述

多段正文使用空行作分段间隔。 但是,最好不要写太多的内容,也就不用分段。

注释是可选内容,只有两种情况:

  • 不兼容变动描述:以 BREAKING CHANGE 开头,描述变动情况、理由和迁移方法
  • 关闭 issue:注意提供 issue 的 ID

特殊情况

如果提交用来撤销以前的提交内容,则格式是固定的:

  1. 必需以 revert: 开头,后面紧跟被撤销的提交的完整标题
  2. 正文只有一句:Revert commit <SHA-code>(或者中文:撤销提交 <SHA-code>),SHA-code 为被撤销提交的 SHA 标识符

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
feat: Summarize changes in around 50 characters or less

More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequenses of this
change? Here's the place to explain them.

Further paragraphs come after blank lines.

- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here

If you use an issue tracker, put references to them at the bottom,
like this:

Resolves: #123
See also: #456, #789

本文参考

Udacity Git Commit Message Style Guide

Commit message 和 Change log 编写指南