Ocavue's Blog
[译] Udacity Git 提交信息风格指导 2018-09-25

原文链接:http://udacity.github.io/git-styleguide/

译者链接:https://github.com/asheraScout

翻译以授权,版权归 Udaacity 所有

# 介绍

这份风格指导应该在你的项目中作为官方指导使用。Udacity evaluators 会使用这份指导来对你的项目评分。对开发来说,什么样才是一个“完美”的风格很多人都有不同的见解。因此,为了减少到底应该使用何种风格的困惑,对在项目课程内的同学,我们强烈建议大家都参考这份指导。

# 提交信息

# 信息结构

一个提交信息应该包含三个独立的部分:标题、可选的主体和一个可选的脚注。三个部分中间使用一个空行间隔。格式如下:

type: subject

body

footer

概要包含提交类型和主题

# 提交类型

提交类型包含以下几种:

  • feat:新功能
  • fix:修 bug
  • docs:文档修改
  • style:格式化;没有代码改动
  • refactor:重构生产代码
  • test:添加测试,重构测试;没有生产代码改动
  • chore:更新构建任务,包管理配置等;没有生产代码改动

# 主题

主题应该不超过50个字符,首字母大写且结尾不加句号。

描述提交使用祈使语气,而不是提交改动的东西。比如,用“修改”,而不是“xx被修改”或者“有xx改动“。

# 描述

不是所有的提交都需要描述,对简单的提交来说,描述是可选的。如果提交需要一些解释或者上下文,你可以写描述。使用描述来解释提交的细节和原因,而不是具体如何实现。

描述和标题之间必须加上空行,描述一行不要超过72个字符。

# 脚注

脚注也是可选的,通常用来标示 issue ID, git 提交 hash 或者相关 url 等。

# 一个提交信息例子

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 所有