git log 只显示一个提交id

标签 git git-commit git-log

我需要一些帮助。可以只显示一个 commit id 吗?由于 git log -3 显示 1 - 3 的日志,我只想显示 3。什么可能的命令会匹配它?

我使用命令

       git log -3 --pretty=format:"%h"

结果是

       ffbef87
       cf0e073
       1c76c5d

我只想显示1c76c5d

最佳答案

你可以使用git show referencing the third parent来自您当前的提交(即 HEAD 的第二个祖先)。此外,git show 接受与 git log 相同的格式字符串:

git show HEAD~2 --pretty=format:"%h" --no-patch

更新(2016-12-01)

更好的方法是使用 rev-parse plumbing command使用 --short 选项输出缩写的(7 个字符)提交 SHA-1:

git rev-parse --short HEAD~2

或者您也可以指定提交 SHA-1 的确切长度:

git rev-parse --short=4 HEAD~2

关于git log 只显示一个提交id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31448445/

相关文章:

git - 事后从 git 存储库中删除二进制数据

windows - Windows 上的 Git : Why I suddenly have untracked directory that used to be tracked?

Git 在过去的提交中更改用户的凭据而不更改历史记录(提交日期)

Git 提交失败 : "Please supply the message using either -m or -F option."

r - 撤消 Rstudio 中太大而无法推送的 git commit

Git - 跟踪分支信息

git - 如何修复 GIT 错误 : HEAD: invalid reflog entry xxxxxxxxxxxxxxxx

Git 不会添加某些 glob

Git - 为什么在已删除文件上运行命令时需要双破折号?

GIT存储库: "invalid author/committer line - missing space before date"