Content-addressable storage
The conceptWhy Git doesn't store a new copy of every file each time you commit
In content-addressable storage, each piece of data is named by a hash of its own bytes, not by a location you choose. A hash function turns any input into a short fingerprint; the same bytes always give the same one.
Git works this way. On each commit, Git hashes every file's contents and stores it in .git/objects under that hash. A README unchanged for 50 commits gets the same hash each time, so Git keeps one copy.
What it’s forGives each piece of data its address in the store.
address = H(content)
- H
- a cryptographic hash function, e.g. SHA-1 in Git, which gives 40 hexadecimal characters
- content
- the exact bytes being stored (Git adds a short header with the type and size first)
- address
- the key used to save and later find the data
What it givesA name that is the same for identical bytes and completely different if even one byte changes.
- README unchanged in 3 commits → same bytes → same hash → stored once
- Change one letter → different bytes → new hash → one new object
- 3 commits store 2 README objects, not 3