Ask anything about this article
Hi! I've read this article.
What would you like to know?
@farhan

If you have spent any time looking at a pull request you already know the familiar green and red lines that GitHub, GitLab or Bitbucket display. The instinctive reaction is to think Git is a diff tool. The headline from Dev.to – "Git Isn't a Diff Tracker: How Blobs, Trees, DAG Commits, and the Index Actually Work Under the Hood" – sparked a wave of discussion on Hacker News and Twitter. Developers are re‑evaluating old mental models, and the conversation is heating up because the implications touch performance, security, and how we build tooling.
Hot take: Treating Git as a diff engine is the biggest misconception in modern software engineering; it blinds us to the real power of its content‑addressed storage.
This article unpacks the actual architecture, explains why diffs are a presentation layer, and argues why understanding the internals can make you a better engineer.
Git stores everything as immutable objects identified by SHA‑1 (or SHA‑256 in newer versions) hashes. There are three primary object types:
A blob is simply a byte‑array of a file. Git does not store the filename; the filename lives in the tree. Because blobs are content‑addressed, identical files across the repo share the same object. This deduplication is why a massive monorepo can still be surprisingly small.
Think of a tree as a folder. It contains entries of the form (mode, type, hash, name). A tree can point to other trees, creating a hierarchical representation of the file system at a point in time. The tree is what makes Git snapshot‑oriented rather than change‑oriented.
A commit ties everything together:
tree hash – the root tree of the snapshot.parent hashes – one or more ancestors, forming a Directed Acyclic Graph (DAG).The DAG gives Git its powerful branching and merging capabilities. Each commit is a complete view of the project, not a delta.
The index (or staging area) is a cached version of the tree that reflects what will become the next commit. It holds the path‑to‑blob mapping and file mode information. When you run git add, Git writes the new blob (if needed) and updates the index entry. When you commit, Git writes a new tree based on the index and then a commit object.
The familiar diff view is generated on demand by comparing two trees (or a tree and a blob). Git's diff command walks the two trees, finds changed blobs, and runs a line‑by‑line comparison algorithm. The diff is computed, not stored. This design has several consequences:
CI systems that rely on git fetch --depth=1 can checkout only the latest snapshot without pulling a history of diffs. Understanding that each commit is a full snapshot lets teams design shallow clones that still provide reliable builds.
Because blobs are immutable and content‑addressed, tampering is detectable: the hash would change. Tools that scan for secrets can focus on blob contents without worrying about hidden diffs.
Git's three‑way merge works on tree structures, not line diffs. Knowing this helps developers choose strategies like ours or theirs for binary assets where line‑based diffs are meaningless.
| Trend | What It Means for Developers |
|---|---|
| Git‑LFS and Large File Support | Stores large binaries as pointer files; the underlying blob model stays the same, reinforcing the snapshot view. |
| Partial Clones & Sparse Checkout | Leverages the fact that commits are snapshots; you can fetch only needed blobs, reducing bandwidth. |
| Git as a Content Store for AI Models | Emerging tools treat Git as a versioned data lake for model weights, relying on content addressing for reproducibility. |
| Enhanced Diff Algorithms (semantic, AI‑assisted) | Since diffs are computed, new algorithms can be plugged in without changing storage format. |
Developers are beginning to treat Git less as a "diff manager" and more as a distributed content‑addressed database. This shift is evident in the rise of Git‑centric CI platforms, data‑versioning tools like DVC, and even in the discussion around Valen's Memory Safety borrow‑checking proposals, which borrow concepts from Git's immutable object model.
By internalizing these facts, you can write more efficient CI pipelines, avoid common pitfalls in large‑repo management, and contribute to the next generation of Git‑based tools.
Feel free to share your own Git myths in the comments – the conversation is just getting started.