If you search for %b and %B in the documentation, there is no explanation of the difference between them apart from the cryptic "(unwrapped subject and body)".
Here is an example commit from a repo (using git version 2.9.3) and the differing result printed from using %b vs. %B. The commit command was git commit -m 'Automated version update from Jenkins.'
$ git log -1 origin/master
commit 30ac57e...
Author: Jenkins <email@email.com>
Date: Wed Jul 12 16:28:41 2017 +0000
Automated version update from Jenkins.
$ git log -1 --format=%B origin/master
Automated version update from Jenkins.
$ git log -1 --format=%b origin/master
$
I do not understand why %b fails to produce the commit message body, nor why %B (if it contains "subject and body" in some sense) only provides the message body.
What is the underlying difference between %b and %B for pretty printing from logs?
If you want to reliably print just the most recent commit message (message only), how should you do so? I thought it should be git log -1 --format=%b origin/master
but this example seems to suggest otherwise. Will %B work reliably, or does the phrase "(unwrapped subject and body)" mean it may somehow include the subject in some situations?
The commit that you're looking at doesn't have a body, so %b
is correctly printing nothing. The "subject", also called the "title line" elsewhere in the same doc, is everything between the headers and the next blank line, and that's the only kind of message your commit has. The body is everything from that first blank line onwards.
Illustrating with a different commit:
$ git log -1 51e6467fdc073a9a5149b4c12ca9d79d6ac46872^!
commit 51e6467fdc073a9a5149b4c12ca9d79d6ac46872
Author: Andrew Rodland <andrew@cleverdomain.org>
Date: Fri Mar 14 14:22:02 2014 -0400
Make the event data be the master that owns the socket, instead of the socket
Then we will be able to access the master's domains and other info later
on
$ git log --format=%B 51e6467fdc073a9a5149b4c12ca9d79d6ac46872^!
Make the event data be the master that owns the socket, instead of the socket
Then we will be able to access the master's domains and other info later
on
$ git log --format=%b 51e6467fdc073a9a5149b4c12ca9d79d6ac46872^!
Then we will be able to access the master's domains and other info later
on
"Unwrapped" simply means that the subject will have any line-wrapping removed (although convention is that it shouldn't be longer than a line anyway, git doesn't enforce that).