Skip to content

Git commit message guidelines

richardkchapman edited this page Aug 13, 2012 · 8 revisions

The first line of the commit message must start with gh-NNNN where NNNN is the GitHub issue number being addressed, followed by a short description of the issue, which should start with a capital letter and should not end with a the full stop. The total line length should be no more than 80 characters.

The body should provide a meaningful commit message, which:

  • uses the imperative, present tense: “change” not “changed” or “changes”. Describe what the effect of applying the change will be, not what you did do make the change.

  • includes motivation for the change, and contrasts its implementation with previous behaviour.

  • Wrap lines at no more than 80 charaters

See

for some justifications on this strategy

An example commit message:

gh-nnnnn Short summary of the issue

More detailed explanatory text, if necessary.  Wrap it to no more than
80 characters.  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 present tense: "Fix bug" and not "Fixed
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, preceded by a
  single space, with blank lines in between, but conventions vary here

- Use a hanging indent

One way to approach the writing of commit messages is to consider the audience, and where each message will end up. Write the 1st line on the assumption you are writing a line in the 'short' changelog of the next release. Write the body on the assumption that the reader could be trying to work out if an issue they have seen could be related to this change, OR looking at a change in the code trying to work out why it was done. At the bottom, if appropriate, add a final line referencing any bug numbers, being careful to use the syntax that GitHub recognizes in order to link or automatically close issues - use Fixed gh-XXXX. if the associated issue can be closed once this change is merged.

NOTE: These guidelines refer to the git commit message and not any github comment fields used for discussing a commit, pull-request, or line. The github comment fields do not form part of the project's git history. When submitting a pull request there is no need to put anything in the pull-request's comment field in most cases - the commit messages should already explain the reason for the request. Comments on the pull-request might be useful for such things as "this pull request is dependent on you having taken that other one" or suchlike...