在git中打印给定提交的提交消息

wz3gfoph  于 2023-06-04  发布在  Git
关注(0)|答案(8)|浏览(230)

我需要一个plumbing命令来打印一个给定提交的提交消息--不多不少。

h22fl7wq

h22fl7wq1#

这不是“管道”,但它会做你想要的:

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

如果你绝对需要一个“plumbing”命令(不知道为什么需要),你可以使用rev-list

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

尽管rev-list除了打印提交消息外,还会打印提交sha(在第一行)。

plupiseo

plupiseo2#

git showgit log更像是一个管道命令,并且具有相同的格式选项:

git show -s --format=%B SHA1
zed5wv10

zed5wv103#

不是管道,但我在我的.gitconfig中有这些:

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

这是“最后摘要”和“最后留言”。您可以提供一个提交以获取该提交的摘要或消息。(我使用的是1.7.0.5,所以没有%B。)

cxfofazt

cxfofazt4#

这将为您提供一个非常紧凑的列表,其中包含任何指定时间的所有消息。

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

pzfprimi5#

我开始用

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

它似乎比

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

两者给予相同的结果
实际上,我写了一个小工具来查看我所有回购的状态。你可以在github上找到它。

j8ag8udp

j8ag8udp6#

使用git-rev-list打印提交消息

git-rev-list是一个plumbing命令,让你打印提交的消息。
像这样使用它。

git rev-list --max-count=1 --no-commit-header --format=%B <commit>
  • --max-count=1:我们只对一个提交感兴趣
  • --no-commit-header:不显示默认提交头
  • --format=%B:显示消息(主题%s + %n%n+正文%b
  • <commit>:a shaHEADbranch-nametag-namebranch1...branch2

它比git loggit show快得多。

6yt4nkrj

6yt4nkrj7#

我使用shortlog来实现:

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

mcdcgff08#

在git中单独获取我的Last Commit Message
git log --format=%B -n 1 $(git log -1 --pretty=format:"%h") | cat -

相关问题