在 git 中打印给定提交的提交消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3357280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Print commit message of a given commit in git
提问by Mark Probst
I need a plumbing command to print the commit message of one given commit - nothing more, nothing less.
我需要一个管道命令来打印一个给定提交的提交消息 - 仅此而已。
回答by mipadi
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
:
如果你绝对需要一个“管道”命令(不知道为什么这是一个要求),你可以使用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.
虽然rev-list
除了提交消息之外还会打印出提交 sha(在第一行)。
回答by CharlesB
git show
is more a plumbing command than git log
, and has the same formatting options:
git show
与其说是管道命令,不如说是一个管道命令git log
,并且具有相同的格式选项:
git show -s --format=%B SHA1
回答by bstpierre
Not plumbing, but I have these in my .gitconfig:
不是管道,但我的 .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.)
那是“最后总结”和“最后一条消息”。您可以提供提交以获取该提交的摘要或消息。(我使用的是 1.7.0.5,所以没有 %B。)
回答by Harshniket Seta
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
回答by mja
I use shortlog for this:
我为此使用shortlog:
$ git shortlog master..
Username (3):
Write something
Add something
Bump to 1.3.8
回答by nos
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
两者都给出相同的结果