Lojic Technologies

Archive for August 2010

Git commit message style

leave a comment »

I just learned something about how git handles multi-line commit messages. If a commit message has a blank second line, git will treat the first line as the “subject” and the 3rd and following lines as the “body”. This will allow some nice things to be done with the git log command.

For example, the following command:

git log --pretty=format:"%ai %an: %s%n%n%b%n"

Will produce output such as this:

2010-08-30 13:10:51 -0400 Brian Adkins: This is my second commit for this example.

And this is the body for the second commit.
Second line of the body.

2010-08-30 13:07:23 -0400 Brian Adkins: This text will be treated as the subject.

This text will be treated as the body. The subject should be
a short summary of the commit since you may want to show just
the subject on some git log invocations.

If you just want to see the “subject”, use:

git log --pretty=format:"%ai %an: %s%n"

Which will display as follows:

2010-08-30 13:10:51 -0400 Brian Adkins: This is my second commit for this example.

2010-08-30 13:07:23 -0400 Brian Adkins: This text will be treated as the subject.

See “git log –help” for various formatting specifications.

Thanks to Nathaniel Talbott for the chat message that prompted me to look into this.

Written by Brian Adkins

August 30, 2010 at 12:15 pm

Posted in programming

Tagged with