How Git Stores Your History
Not diffs — a tree of snapshots addressed by their own hash.
Most people picture Git storing the changes between versions. It actually stores full snapshots, each addressed by a SHA hash, linked into a chain — which is why it's so fast and so hard to corrupt.
Legend — how to read this diagram
The four objects
- Blob. The raw contents of a file. Identical files anywhere share one blob.
- Tree. A directory listing: names pointing to blobs and other trees.
- Commit. A snapshot: a pointer to one tree, parent commit(s), author, and message.
- Tag. A named pointer to a specific object, usually a release.
Why hashing everything matters
Content addressing. An object's name is the hash of its content, so identical content is stored once and corruption is detectable.
Cheap branches. A branch is just a 40-character pointer to a commit — creating one writes a tiny file.
Integrity. Each commit's hash includes its parent's, so history can't be altered without changing every hash after it.
Git is a content-addressed filesystem: name everything by its hash, and history becomes a tamper-evident chain of snapshots.
No comments:
Post a Comment