Today I'm learning some basic git knowledge via reading this doc online:
http://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-Hi
And at that chapter, I'm start to learn using git log --pretty=format:" "
to show log info at my taste.
But some how, I saw in the format table two similar options, %H
for Commit Hash
, %P
for Parent Hash
and %T
for Tree Hash
.
I experimented them on my command line, it comes out they are all hash values of same length with different value.
I googled and stackoverflowed, no obvious hints so far.
I have idea about this Hash value
, it's a checksum of that git commit.
But what does Parent Hash
and Tree hash
do?
- PS: Ah, I got some ideas now, did the
Parent Hash
mean the hash value of the directly origin of a branch?
Best Answer
Parent hashes:
You can see commit4 and commit3 is parent of commit5, commit2 is parent of commit3 and commit4, commit1 is parent of commit2.
Tree hash:
The command's function: Pretty-print the contents of
<object>
based on it's type.In git,all the content is stored as tree and blob objects, with trees corresponding to UNIX directory entries and blobs corresponding more or less to inodes or file contents. A single tree object contains one or more tree entries, each of which contains a SHA-1 pointer to a blob or subtree with its associated mode, type, and filename. Git normally creates a tree by taking the state of your staging area or index and writing a series of tree objects from it. Commit objects have the information about who saved the tree object, when they saved or why they were saved. This is the basic information that the commit object stores for you.
Conclusion:
Commit hash, Parent hash, Tree hash are all SHA-1. Commit hash and Parent hash is identical except Parent hash has child. Tree hash is represent a Tree object. Commit hash and Parent hash represent a commit object.
Reference:
Git Internals - Git Objects
git-cat-file - Provide content or type and size information for repository objects