Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Better Git Commit Messages

Better Git Commit Messages

git commit -asm "Write better commit messages."

David Celis

August 17, 2012
Tweet

More Decks by David Celis

Other Decks in Programming

Transcript

  1. Typical Commit Message $ git log --no-merges commit 8c052211839afc7373026308e8bda74721e04adc Author:

    Everybody Ever <[email protected]> Date: Wed Aug 15 00:09:29 2012 -0700 fixed some bugs Friday, August 17, 12
  2. Better Commit Messages Have a more descriptive body using the

    present imperative tense (in other words, commands) Friday, August 17, 12
  3. commit 30b6769ff4b0cae0272a9d48c3397c0fdc7987ee Author: David Celis <[email protected]> Date: Wed Aug 15

    00:09:29 2012 -0700 Summary of changes (< 50 characters) If necessary (helpful on a team), a more descriptive and verbose summary of changes. The body of the commit message should be wrapped to 72 characters for proper formatting during a `git log`. Use the imperative present tense (i.e. commands). Instead of saying something like "Fixed a few bugs for..." or "Fixing a few bugs for...", say "Fix a few bugs for..." # ... Better Commit Messages Friday, August 17, 12
  4. commit 30b6769ff4b0cae0272a9d48c3397c0fdc7987ee Author: David Celis <[email protected]> Date: Wed Aug 15

    00:09:29 2012 -0700 # ... Unless you omit the body of the commit message, the blank line between it and the subject is critical. Tools such as `git-rebase` will get confused if the two run together. It is typical to separate paragraphs within the body by blank lines as well, just as you would while writing anything else. # ... Better Commit Messages Friday, August 17, 12
  5. commit 30b6769ff4b0cae0272a9d48c3397c0fdc7987ee Author: David Celis <[email protected]> Date: Wed Aug 15

    00:09:29 2012 -0700 # ... Depending on the context of the commit message, the subject line and body will be treated differently. For instance: * In a GitHub pull request, the first line becomes the subject. The rest of the message will be parsed for Markdown, which is awesome. * In an email, the first line becomes the subject and the rest of the commit message becomes the body. * Hyphens are also okay for bulleted lists. Precede all bullets by one space. # ... Better Commit Messages Friday, August 17, 12
  6. commit 30b6769ff4b0cae0272a9d48c3397c0fdc7987ee Author: David Celis <[email protected]> Date: Wed Aug 15

    00:09:29 2012 -0700 # ... Finally, code should be indented by four spaces in any context. Signed-off-by: David Celis <[email protected]> Better Commit Messages Friday, August 17, 12