Git & GitHub Interview Question #118

What are Git objects?

Advanced GitHub Actions, Repository Internals, Submodules, LFS & Diagnostic Tools Senior Advanced

Quick Interview Answer

Git's object database is built primarily around blobs, trees, commits, and annotated tag objects. Blobs store file content, trees describe directory snapshots, commits connect a tree to parent history and metadata, and tag objects can provide annotated references.

Detailed Explanation

Git's object database is built primarily around blobs, trees, commits, and annotated tag objects. Blobs store file content, trees describe directory snapshots, commits connect a tree to parent history and metadata, and tag objects can provide annotated references.

Git addresses objects by cryptographic object IDs derived from their content and type information. Understanding this model explains why Git can efficiently represent snapshots and history.

Code Example

# Inspect an object's type
git cat-file -t HEAD

# Inspect a commit
git cat-file -p HEAD