Git commit message rule
  • Written by Liang Zeng
  • May 18th, 2014
  • About git

Git commit message rule

git commit 信息基本规则

Here’s a model Git commit message:

    Capitalized, short (50 chars or less) summary # 主题

    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.

    Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
    or "Fixes bug."  This convention matches up with commit messages generated
    by commands like git merge and git revert.

    Further paragraphs come after blank lines.

    - Bullet points are okay, too

    - Typically a hyphen or asterisk is used for the bullet, followed by a
    single space, with blank lines in between, but conventions vary here

    - Use a hanging indent # 讨论issue链接
  • 总是编写提交信息,好像你在向正坐在你旁边且完全不知道整个事情缘由的同事解释此次改动,回答下面的问题:
  1. 为什么此次改动是必需的?
  2. 它是如何解决问题的?
  3. 这次改动有什么副作用?
  4. 考虑包含一个[to the discussion.] 的链接。
  • 避免在一次提交中有不相关的改动。你可能在一个已经做了其它改动的同一个文件里发现了一个错字或做了微小的代码重构,但是一定要抵制诱惑与主要的改动一起记录,除非它们是直接相关的。

  • 在push之前总是清除你的历史。如果提交还没有被共享,那么重新修订它们中不好的部分是安全的。下面的可能是Faraday项目的永久历史,但是我最终把它压缩为仅2次提交,并编辑它们的信息以隐藏我首次设置脚本遇到了麻烦这样一个事实。

  • 避免不相关改动间的推导: 坚持基于行的编码风格,允许你添加,编辑或删除列表中的值而不用改动相邻行。

Hey There!
What is This?