Get information about a SHA-1 commit object?

Git

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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

This is an answer to https://stackoverflow.com/questions/7663451/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 https://stackoverflow.com/questions/7663451/view-a-specific-git-commit

Use

git show --no-patch <SHA1>

if you want author and date information too.

Solution 3 - Git

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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVaibhav BajpaiView Question on Stackoverflow
Solution 1 - GitCharlesBView Answer on Stackoverflow
Solution 2 - GitIvanView Answer on Stackoverflow
Solution 3 - GitSaikatView Answer on Stackoverflow