在 Git 中通过哈希 SHA 查找提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14167335/
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
Find commit by hash SHA in Git
提问by Ghadeer
I need to find a commit in Git by a given hash, SHA. For example, if I have the "a2c25061" hash, and I need to get the author and the committer of this commit.
我需要通过给定的哈希值 SHA 在 Git 中找到一个提交。例如,如果我有“a2c25061”散列,我需要得到这个提交的作者和提交者。
What is the command to get that?
得到它的命令是什么?
回答by Pavan Yalamanchili
Just use the following command
只需使用以下命令
git show a2c25061
回答by Greg Bacon
git log -1 --format="%an %ae%n%cn %ce" a2c25061
The Pretty Formats section of the git show
documentationcontains
format:<string>
The
format:<string>
format allows you to specify which information you want to show. It works a little bit like printf format, with the notable exception that you get a newline with%n
instead of\n
…The placeholders are:
%an
: author name%ae
: author email%cn
: committer name%ce
: committer email
format:<string>
该
format:<string>
格式允许您指定要显示的信息。它的工作原理有点像 printf 格式,但值得注意的例外是你得到一个换行符%n
而不是\n
……占位符是:
%an
: 作者姓名%ae
: 作者邮箱%cn
: 提交者姓名%ce
: 提交者邮箱
回答by Yamona
There are two ways to do this.
有两种方法可以做到这一点。
1. providing the SHA of the commit you want to see to git log
1.提供你想看到的提交的SHA到git log
git log -p a2c25061
git log -p a2c25061
Where -p
is short for patch
-p
补丁的缩写在哪里
2. use git show
2. 使用 git 显示
git show a2c25061
git show a2c25061
The output for both commands will be:
这两个命令的输出将是:
- the commit
- the author
- the date
- the commit message
- the patch information
- 提交
- 作者
- 日期
- 提交消息
- 补丁信息