Git Objects

Git stores data using objects. The core object types are blob, tree, commit, and tag. Blobs contain file contents, trees describe directory structures, commits point to trees and parent commits, and annotated tags can point to Git objects with metadata.

Objects are addressed by cryptographic object IDs.

Git Object Model
Inspect an Object
git cat-file -t HEAD
git cat-file -p HEAD
git cat-file -t HEAD^{tree}
git rev-parse HEAD
💡 cat-file can inspect Git objects. rev-parse resolves references such as HEAD to their object IDs.
Key Takeaways
  • Git stores content as objects rather than storing a sequence of file copies.
  • Commits point to trees and parent commits.
  • Object IDs provide stable content-addressed references.
Knowledge Check

Which Git object stores file contents?