views:

44

answers:

3

I need a plumbing command to print the commit message of one given commit - nothing more, nothing less.

A: 
git log ... | grep -vE "^(commit|Author|Date)"
qbi
That's neither plumbing nor one command.
Mark Probst
+1  A: 

It's not "plumbing", but it'll do exactly what you want:

$ git log --format=%B -n 1 <commit>

If you absolutely need a "plumbing" command (not sure why that's a requirement), you can use rev-list:

$ git rev-list --format=%B --max-count=1 <commit>

Although rev-list will also print out the commit sha (on the first line) in addition to the commit message.

mipadi
No, it won't. First of all, %B is not a correct format specifier - the one you mean is %b. Second, it doesn't show the whole commit message, only what it considers the "body". Third, even if you force it to print the "subject" as well, it doesn't do so properly with commit messages that don't conform to the subject/body convention (it eats newlines), like this one: http://github.com/mono/mono/commit/e43c207e128f8f86c6ddc7989f3a1b611a193845
Mark Probst
Worked perfectly for me - but I used `%s%b` instead of `%B` (on a Linux box)
adamk
`%B` is a correct specifier (at least, in Git 1.7.2, not sure when it was added).
mipadi
`%B` was added sometime after 1.7.1 (probably in 1.7.1.1).
mipadi
Indeed it is - Git 1.7.2 apparently. Muchas gracias!
Mark Probst
A: 

Not plumbing, but I have these in my .gitconfig:

lsum = log -n 1 --pretty=format:'%s'
lmsg = log -n 1 --pretty=format:'%s%n%n%b'

That's "last summary" and "last message". You can provide a commit to get the summary or message of that commit. (I'm using 1.7.0.5 so don't have %B.)

bstpierre