Author: Chris Belanger
By Jawwad Ahmad
Converting short hash into long Execute the command below to convert a short hash into its long equivalent: git rev-parse d83ab2b
The Git object repository structure When Git stores objects, instead of dumping them all into a single directory, which would get unwieldy in rather short order, it structures them neatly into a tree. Git takes the first two characters of your object’s hash, uses that as the directory name, and then uses the remaining 38 characters as the object identifier
You can’t take a look at this object directly, though, as objects in Git are compressed
Git provides a way to look at the contents of a compressed Git object: git cat-file. This decompresses the object and writes it out to your console in a human-readable form. You can simply pass it a short or long hash, and Git will write out the contents of that object in a human-readable form.
git cat-file -p d83ab2b
The -p option here tells Git to figure out what type of object it’s dealing with and to provide appropriately formatted output
Git tells me the details about my chosen commit object: tree c0425d3b2aa2bfbbc0a08efda69ed00286dec6e4
There’s a wealth of information here, but what you’re interested in is the tree hash. The tree object The tree object is a pointer to another object that holds the collection of files for this commit. So execute git cat-file again to see what’s inside that object, substituting your particular hash: git cat-file -p c0425d3b2aa2bfbbc0a08efda69ed00286dec6e4
I get the following information about the tree object: 100644 blob 8b23445f4a55ae5f9e38055dec94b27ef2b14150 LICENSE 100644 blob f5c651739ff232f6226d686724f3c9618dd9f840 README.md 040000 tree d27f2eb006fff5b83fdc5d6639c7cfabdcf9fc37 articles 040000 tree 0b2d0890591a57393dc40e2155bff8901acafbb6 books 040000 tree 028f2d5e0a0f99902638039794149dfa0126bede videos Ah — that looks a lot like the working tree of the project from the first part of this book, doesn’t it? That’s because that’s precisely what this is: a compressed representation of your file structure inside the repository
You can dig further into the tree by following the references down. What’s inside the articles directory in this commit? The following command will tell you that: git cat-file -p d27f2eb006fff5b83fdc5d6639c7cfabdcf9fc37
The blob object For instance, you can see the state of the LICENSE file in this commit with git cat-file: git cat-file -p 8b23445f4a55ae5f9e38055dec94b27ef2b14150