BeCuriouzBeCuriouz

Learn something new every day

🛠️ Tools & Services
🌳

Git Doesn't Store Your Changes. It Stores Snapshots.

💡 Git stores your project as snapshots linked to their parent commits, and a branch is only a tiny pointer to one commit, which is why branching costs almost nothing.

Git is the version control system used by almost every software team. It records the history of a project, lets many people work on the same code in parallel, and lets you undo almost any mistake. Many people assume Git works by saving a list of edits ("line 12 changed"). Some older systems worked that way, but Git doesn't. Its own docs describe it as storing a stream of snapshots: each commit records what the whole project looked like at that moment.

The key is content addressing. Git saves each file and folder in its internal database under a SHA-1 hash of its contents, which is a 40-character fingerprint, instead of under its filename. If a file hasn't changed, its fingerprint hasn't changed either, so the new snapshot just points at the copy already stored. Identical content is kept only once, which keeps snapshots cheap. (To save even more disk space, Git later compresses objects into packfiles.) The hashes also give Git integrity: if anything is altered or corrupted, its fingerprint no longer matches, so Git can tell.

This also explains why branches in Git are so cheap. A commit is a snapshot plus a link to its parent commit. A branch is just a lightweight movable pointer to one commit: a small file holding that commit's hash. Creating a branch writes 41 bytes. Making a new commit moves the pointer forward. HEAD is one more pointer that records which branch you're on.

This design is a big reason Git spread so widely. Older systems often made branching slow and painful, so teams avoided it. In Git, starting a branch for a quick experiment costs almost nothing, and that changed how developers work.

🌳 Git Doesn't Store Your Changes. It Stores Snapshots. — BeCuriouz