Git 提交信息格式指南

Table of Contents

不知道你有没有这样的感觉,不管是 SVN 还是 Git,提交代码的时候 commit 格式总是不好拿捏,不知道应该以什么样的格式提交才「算好」。今天看到一篇文章,总结了 Git 提交信息指南,觉得还不错。因为是英文的,就翻译了一下,意译非直译。

标题:Udacity Git Commit Message Style Guide


1. 消息格式(Message Structure)

提交消息由用空行分割的三部分组成:标题、可选的 body 、可选的 footer。布局看起来像这样:

type: subject




2. 类型(The Type)


  • *feat*:新特性
  • *fix*:Bug 修复
  • *docs*:修改文档
  • *style*:格式化,缺少冒号,等等,没有代码的修改
  • *refactor*:重构生产代码
  • *test*:添加测试用例,重构测试代码,没有生产代码的修改
  • *chore*:更新构建任务、包管理工具配置等等;没有生产代码修改

3. 主题(The Body)

主题不应该超过 50 个字符,以大写字母单词开始,不要以句号结束。

精简的描述提交做的事情,而不是做了什么。比如使用 change/,而不是 /changed 或者 /changes/。

4. 内容(The Body)

不是所有的提交都需要写丰富的 body,只有提交内容需要解释和有上下文的时候才需要写,所以是可选的。使用 body 是用来解释提交的 what 和 *why*,而不是 *how*。

当写 body 的时候,在标题和 body 之间留一个空行,每行不能超过 72 个字符。

6. 提交消息举例

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 好像是一家国际化的培训教育公司。

First created: 2018-07-09 20:35:44
Last updated: 2021-11-15 Mon 10:18
Power by Emacs 27.1 (Org mode 9.4.4)