Git - Working directly with Git Objects
Revision as of 10:00, 23 June 2015 by Jshankar (1 revision imported: EdWiki -- From Shukra)
GitLab - Working directly with Git Objects
- Explore the structure of the object store
- Learn how to use the SHA1 hashes to find content in the repository
Now let’s use some tools to probe git objects directly.
- Finding the Latest Commit
git hist --max-count=1
This should show the latest commit made in the repository.
- Dumping the Latest Commit
- Using the SHA1 hash from the commit listed above …
git cat-file -t <hash> git cat-file -p <hash>
NOTE: If you defined the ‘type’ and ‘dump’ aliases from the aliases slide, then you can type git type and git dump rather than the longer cat-file commands.
This is the dump of the commit object that is at the head of the master branch. It looks a lot like the commit object from the presentation earlier.
- Finding the Tree
We can dump the directory tree referenced in the commit. This should be a description of the (top level) files in our project (for that commit). Use the SHA1 hash from the “tree” line listed above.
git cat-file -p <treehash>
- Dumping the src directory
git cat-file -p <srchash>
There’s the hello.c file.
- Dumping the hello.c file
git cat-file -p <chash>
There you have it. We’ve dumped commit objects, tree objects and blob objects directly from the git repository. That’s all there is to it, blobs, trees and commits.
- Explore On You Own
Explore the git repo manually on your own. See if you can find the original hello.c file from the very first commit by manually following the SHA1 hash references starting in the latest commit.