git,

Git 101: objects

Nov 05, 2022 · 2 mins read · Post a comment

The key part of a Git repo is a key-value data store where each object has its own hash value. Git objects can be found under .git/objects directory. Two noticeably subdirectories when initializing an empty Git repo are: info and pack. Also, there are few types of objects including: blobs, trees, commits and tags.

Prerequisites

  • Git

Solution

An empty Git repo will list the following folders under .git/objects:

  • info
  • pack

The info subdir usually stores a packs file containing list of all .pack files (which I’ll get back to them in a second) and a commit-graph which basically is a binary file that creates a graph out of the Git’s commit history. Regarding new projects, this folder will be empty.

The pack subdir stores .pack files. These pack files are the end result after running the Git garbage collector. I wrote more in details about git gc, so you might want to check that out.

Basically, pack files are compressed loose objects where loose objects being all non-packed objects (files). That’s how Git wants to kick off. Starts creating files as loose objects and then after running git gc pack everything you can.

Related: Git 101: loose vs dangling vs unreachable objects.

For new projects, this folder should be empty too. Otherwise, it contains .idx and .pack files where the latter one being the actual pack file and the former one the index. Both are binary files. Most objects are.

Now, about object types:

  • blobs: binary objects that keep each file’s content.
  • trees: objects storing directory listing. The three important trees including: the Commit history, the Staging area and the Working directory. Related: Git: HEAD vs working tree vs index.
  • commits: objects saving commit’s metadata: author, data, commit message, and the committer (the one who created the commit).
  • tags: objects holding human-readable names referring other Git objects, mostly commits. Related: Git 101: tags.

Conclusion

To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.

git