Unpacking a Git Database

While writing the previous post, I discovered a cool Git command which I thought I’d share.

When you clone a Git repository, most Git hosts will send you a packed version of the database. This is much more efficient than sending the raw Git objects, because duplicate content can be compressed.

However, if you want to inspect the object database with a file browser, it’s hard to do so, because the content stays packed in a single file. Unpacking is pretty simple.

If you unpack the .pack file while it’s in the .git/object/pack folder, Git won’t do anything, because it concludes that it already has all the objects contained in that .pack. However, if you move the .pack file somewhere else, you can unpack it into your repository’s database.

1
2
3
mv .git/object/pack/pack-*.pack .
cat pack-*.pack | git unpack-objects
rm pack-*.pack

And there you have it. Your packed objects are unpacked into .git/objects/ folder.

This isn’t something I recommend doing as a general practice, since it can take up significantly more space, but it’s a useful thing to be able to do if you want to manually inspect your Git database.

I am now accepting new clients for part-time consulting and software development projects. Learn more
Git

I haven't configured comments for this blog, but if you want to get in touch, you can find me on Twitter