Print commit message of a given commit in git

GitCommit Message

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

git show is more a plumbing command than git log, and has the same formatting options:

git show -s --format=%B SHA1

Solution 3 - Git

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.)

Solution 4 - Git

This will give you a very compact list of all messages for any specified time.

git log --since=1/11/2011 --until=28/11/2011 --no-merges --format=%B > CHANGELOG.TXT

Solution 5 - Git

I started to use

git show-branch --no-name <hash>

It seems to be faster than

git show -s --format=%s <hash>

Both give the same result

I actually wrote a small tool to see the status of all my repos. You can find it on github.

enter image description here

Solution 6 - Git

git-rev-list is the plumbing command that let's you print the message of a commit.

Use it like this.

git rev-list --format=%B --max-count=1 <commit> | tail +2
  • --format=%B: show message (subject %s + %n%n + body %b)
  • --max-count=1: we're just interested in one commit
  • <commit>: a sha, HEAD, branch-name, tag-name, branch1...branch2 etc.
  • | tail +2: the first line is the commit sha, skip that

It's a lot faster than git log or git show.

Solution 7 - Git

I use shortlog for this:

$ git shortlog master..
Username (3):
      Write something
      Add something
      Bump to 1.3.8 

Solution 8 - Git

To Get my Last Commit Message alone in git

git log --format=%B -n 1 $(git log -1 --pretty=format:"%h") | cat -

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMark ProbstView Question on Stackoverflow
Solution 1 - GitmipadiView Answer on Stackoverflow
Solution 2 - GitCharlesBView Answer on Stackoverflow
Solution 3 - GitbstpierreView Answer on Stackoverflow
Solution 4 - GitHarshniket SetaView Answer on Stackoverflow
Solution 5 - GitnosView Answer on Stackoverflow
Solution 6 - GitCervEdView Answer on Stackoverflow
Solution 7 - GitmjaView Answer on Stackoverflow
Solution 8 - GitKiruthika kanagarajanView Answer on Stackoverflow