Q: Explain how Git stores data internally. What are blobs, trees, commits, and tags at the object level?
Git is fundamentally a content-addressable filesystem. Every piece of data is stored as an object identified by its SHA-1 (or SHA-256) hash. There are four object types:.
Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "During a major release branch cut, we encountered this exact scenario and used Git internals to recover cleanly. The interviewer is testing: Deep understanding of Git's content-addressable object model.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Initial Diagnostics & Root Cause Analysis
Git is fundamentally a content-addressable filesystem. Every piece of data is stored as an object identified by its SHA-1 (or SHA-256) hash. There are four object types:
- Blob — stores file content (just the raw bytes, no filename or permissions). Two files with identical content share the same blob object, regardless of filename or location. This is how Git deduplicates storage.
- Tree — represents a directory. Contains entries mapping filenames → blob SHAs (for files) or other tree SHAs (for subdirectories), along with file mode (permissions). A tree is a snapshot of a directory at a point in time.
- Commit — points to one tree (the root tree of the project at that moment) and zero or more parent commits. Contains author, committer, timestamp, and message. The first commit has no parent; merge commits have two or more parents. The commit's SHA is a hash of all this — changing anything (message, author, parent, tree) produces a different SHA.
Remediation & Permanent Safeguards
How a commit represents a full snapshot: Each commit stores a complete snapshot, not a diff. Git computes diffs on the fly by comparing two commits' trees. This is why checkout is fast (just materialize one tree) and why branches are cheap (a branch is a 41-byte file containing a commit SHA). Packfiles: for efficiency, Git periodically packs loose objects into packfiles (.pack + .idx), using delta compression (storing diffs between similar blobs) to reduce disk usage. git gc triggers this. Packing is a storage optimization — the logical model is still immutable, content-addressed objects.
commit abc123
└── tree def456 (root directory)
├── blob 111aaa README.md
├── tree 222bbb src/
│ ├── blob 333ccc main.py
│ └── blob 444ddd utils.py
└── tree 555eee tests/
└── blob 666fff test_main.py
- Tag (annotated) — points to a commit (or any object) and adds tagger identity, date, message, and optional signature.
- Blob — stores file content (just the raw bytes, no filename or permissions). Two files with ident...
- Tree — represents a directory. Contains entries mapping filenames → blob SHAs (for files) or othe...
- Commit — points to one tree (the root tree of the project at that moment) and zero or more parent...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring Explain stores data
git push --forceunconditionally overwrites remote commits made by teammates, whereas--force-with-leaseaborts if the remote ref was updated. - Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring Explain stores data Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
-
Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring Explain stores data
git reflogtracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches. - Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring Explain stores data Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.