GIT系列三:commit消息规范


维护一个良好的commit消息格式和规范,是一个优秀项目的重要前提。
本文就先来谈谈commit消息到底该怎么提交。


提交commit的基本原则

1. 以一个小功能、小改进或一个bug fixed为单位
2. 对应的unit test 程序放在同一个commit中
3. 不相关的代码修改不要放在同一个commit
4. 语法错误的半成品程序不能commit

commit消息格式

这部分内容已经在具体的例子:像linux kernel一样管理你的项目描述过。
这里算是正式的整理进入wiki页面了。
至于如何保证做到这么干净利落的commit消息日志,则请移步后续对于rebase等命令的分析。commit的消息格式如下

第一行用一句简短的话总结这个commit  

第一行最好用一个描述性的前缀开始,比如  
  "net:"表示针对net子系统的修改  
  "fix:"表示这是一个bug fix  

第二行为空行

最后可以增加一些详细的描述,用以解释commit具体干了什么,为什么这么干  

commit message格式的一个模板如下,为保持原文含义,直接贴上英文版。

Short (50 chars or less) summary of changes

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 an email 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); tools like rebase can get confused if you run
the two together.

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