git log 只显示一个提交 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31448445/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:23:28  来源:igfitidea点击:

git log show one commit id only

gitgit-commitgit-log

提问by rkevx21

I need some help. It is possible to only show one commit id? Since git log -3 show the log from 1 - 3, I just want to show only 3. What possible command will match for it?

我需要帮助。是否可以只显示一个提交 ID?由于 git log -3 显示 1 - 3 的日志,我只想显示 3。什么可能的命令会与之匹配?

I use the command

我使用命令

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

the result is

结果是

       ffbef87
       cf0e073
       1c76c5d

I only want to display the 1c76c5donly.

我只想显示1c76c5d

采纳答案by Enrico Campidoglio

You can use git showreferencing the third parentfrom your current commit (i.e. the second ancestor from HEAD). Also, git showaccepts the same format string as git log:

您可以使用从当前提交中git show引用第三个父项(即来自 的第二个祖先HEAD)。此外,git show接受与以下相同的格式字符串git log

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

Update (2016-12-01)

更新 ( 2016-12-01)

An even better way would be to use the rev-parseplumbing commandwith the --shortoption to output the abbreviated (7 characters) commit SHA-1:

更好的方法是使用带有输出缩写(7 个字符)提交 SHA-1的选项的管道命令rev-parse--short

git rev-parse --short HEAD~2

Or you could also specify the exact length of the commit SHA-1:

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

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

回答by DylanYoung

There is a tool for that:

有一个工具:

git log -3 --pretty=format:"%h" | tail -n 1

You can include ncharacters of the hash (instead of the default) with the following flag:

您可以n使用以下标志包含哈希字符(而不是默认值):

--abbrev=n 

Relevant pieces of the Unix Philosophy

Unix 哲学的相关部分

1) Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new "features".

2) Expect the output of every program to become the input to another, as yet unknown, program. Don't clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don't insist on interactive input.

... [i.e.]

  • Write programs that do one thing and do it well.
  • Write programs to work together.

1)让每个程序做好一件事。要完成一项新工作,请重新构建而不是通过添加新“功能”来使旧程序复杂化。

2) 期望每个程序的输出成为另一个未知程序的输入。不要用无关信息混淆输出。避免严格的列式或二进制输入格式。不要坚持交互式输入。

... [IE]

  • 编写只做一件事并把它做好的程序。
  • 编写程序一起工作。

https://en.wikipedia.org/wiki/Unix_philosophy

https://en.wikipedia.org/wiki/Unix_philosophy

回答by Andy

Since at least git version 2.3.8, you can use the --skipoption:

由于至少 git 版本 2.3.8,您可以使用该--skip选项:

   git log -1 --skip 2 --pretty=format:"%h"

Not sure which earlier versions of git support --skip.

不确定哪些早期版本的 git 支持--skip