git 获取有关 SHA-1 提交对象的信息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7610073/
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
Get Information about a SHA-1 commit object?
提问by Vaibhav Bajpai
I searched for a topic of interest in a commit log:
我在提交日志中搜索了一个感兴趣的主题:
$ git log --pretty=oneline | grep -i ...
$SHA1 < ... commit message ... >
I now have a SHA1
, and I want to know information about the files affecting that SHA1
and maybe later diff
them with their parent. How can I get this done?
我现在有一个SHA1
, 我想知道有关影响它的文件的信息SHA1
,也许以后diff
他们和他们的父母在一起。我怎样才能做到这一点?
回答by CharlesB
git show <SHA1>
will show the commit date, author, parent, and diff of files that changed from parent commit.
git show <SHA1>
将显示从父提交更改的文件的提交日期、作者、父级和差异。
回答by Ivan
git show --no-patch --oneline <SHA1>
git show --no-patch <SHA1>
This is an answer to View a specific Git commitwhich has no reply box as it has been marked as a duplicate of this question. Some of the people looking for a reply to the above question are likely to follow the link and look for an answer here.
这是查看没有回复框的特定 Git 提交的答案, 因为它已被标记为此问题的副本。一些寻求上述问题回复的人可能会点击链接并在此处寻找答案。
Both are questions about obtaining information about a commit from its SHA1 code.
两者都是关于从其 SHA1 代码获取提交信息的问题。
Some of the time when you have identified a commit by its SHA1 code, you will want to know everything about it: all the changed files, what the actual changes are etc.
有时,当您通过 SHA1 代码识别提交时,您会想知道关于它的一切:所有更改的文件,实际更改是什么等。
The other question is much more specific. Someone had a suspect line of software in a file and had tracked it to a particular SHA1 code using "git blame". They then simply wanted to know which software change in human terms had introduced that line. There is no interest in knowing all the other changed files, no interest in getting a complete diff of the files, or even of getting a diff of that one file. It's simply about knowing which change introduced a line of code.
另一个问题要具体得多。有人在文件中有可疑的软件行,并使用“git blame”将其跟踪到特定的 SHA1 代码。然后,他们只是想知道从人类角度来看是哪个软件更改引入了该产品线。没有兴趣知道所有其他更改的文件,没有兴趣获得文件的完整差异,甚至没有兴趣获得那个文件的差异。这只是关于知道哪个更改引入了一行代码。
Instead of information like
而不是像这样的信息
c27feeaa9b2c6270ff559b21eaf9f1e0317676a7
we want information like
我们想要这样的信息
Humanitarian Aid Feature
or
或者
Left handed Thread Fix
To do that, use
为此,请使用
git show --no-patch --oneline <SHA1>
where git show --no-patch (i.e. with the --no-patch option) is the key to answering eykanal's question View a specific Git commit
其中 git show --no-patch(即使用 --no-patch 选项)是回答 eykanal 问题的关键查看特定的 Git 提交
Use
用
git show --no-patch <SHA1>
if you want author and date information too.
如果您也需要作者和日期信息。
回答by Saikat
You can also get specific information about a commit object (using the SHA1
) using cat-filecommand.
您还可以SHA1
使用cat-file命令获取有关提交对象的特定信息(使用)。
E.g. git cat-file -p <sha1>
例如 git cat-file -p <sha1>
Sample Output:
示例输出:
$ git cat-file -p xxxx
tree <sha1>
parent <sha1>
parent <sha1>
author <author> <unix timestamp>
committer <committer> <unix timestamp>
<commit message>