开发者

Get information about a SHA-1 commit object?

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 informa开发者_如何学Gotion about the files affecting that SHA1 and maybe later diff them with their parent. How can I get this done?


git show <SHA1> will show the commit date, author, parent, and diff of files that changed from parent commit.


git show --no-patch --oneline <SHA1>
git show --no-patch <SHA1>

This is an answer to View a specific Git commit which 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.

Both are questions about obtaining information about a commit from its SHA1 code.

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.

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.

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

Use

git show --no-patch <SHA1>

if you want author and date information too.


You can also get specific information about a commit object (using the SHA1) using cat-file command.

E.g. 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜