Skip to content

Writing good commit messages

Philippe Ombredanne edited this page Mar 3, 2017 · 4 revisions

What is good commit message? We want to avoid this: https://xkcd.com/1296/

Read these articles:

The main style points are these:

Subject:

  • Prefix the subject line with an issue number when available as in "#234"
  • Limit the subject line to 50 characters
  • Capitalize the subject line
  • Do not end the subject line with a period
  • Use the imperative mood in the subject line: you are giving orders to the codebase

Body:

  • Separate subject from body with a blank line
  • Wrap the body at 72 characters. Use only spaces for formatting, not tabs.
  • Use the body to explain what and why vs. how
  • use bullets with a * if needed
  • Add a Reported-by: if needed
  • End your message with a Signed-off-by: prefixed by a blank line

Other comments:

We like to prefix the 1st line with an issue number. If this was a trivial change it may not have one though. If it had one a you would use #156 as a prefix to the first line.

We like to tell why the commit is there and use an imperative style, like if you were giving an order to the codebase with your commit:

e.g rather than : Minor fix for unnecessary operations. may be #123 Remove unnecessary operations. or

#123 Remove unnecessary operations

   * If the ts timestamp does not exist, do not compare 
     with old one.
  1. You need to add a signoff to your commit. So the final message would have looked like this:
#123 Remove unnecessary operations

   * If the ts timestamp does not exist, do not compare 
     with old one.

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Clone this wiki locally