Search code examples
gitcommit-message

Print commit message of a given commit in git


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


Solution

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