Quantcast
Channel: Lojic Technologies Blog: Lojic Technologies Blog
Viewing all articles
Browse latest Browse all 84

Git commit message style

$
0
0

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.


Viewing all articles
Browse latest Browse all 84

Trending Articles