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) ha...
🛠️ Production Runbook & Step-by-Step Resolution
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. --- ## 🟣 Diffing, Logging & Code Archaeology
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...