Print commit message of a given commit in git

后端 未结 6 1908
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 10:10

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

相关标签:
6条回答
  • 2020-11-27 10:48

    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
    
    0 讨论(0)
  • 2020-11-27 10:49

    I use shortlog for this:

    $ git shortlog master..
    Username (3):
          Write something
          Add something
          Bump to 1.3.8 
    
    0 讨论(0)
  • 2020-11-27 10:52

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

    git show -s --format=%B SHA1
    
    0 讨论(0)
  • 2020-11-27 10:52

    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

    0 讨论(0)
  • 2020-11-27 10:56

    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.

    0 讨论(0)
  • 2020-11-27 10:58

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

    0 讨论(0)
提交回复
热议问题