Content-Addressable Storage

Git as a Content-Addressable Filesystem

At its core Git 1,932 is a key-value store: you give it content and it returns a key computed from that content, its SHA-1 hash. The same content yields the same key on any machine, so the key is both a name and a checksum. Git's documentation calls this a content-addressable filesystem:

Storing content in Git's object databaseShell
git init objects-lab
cd objects-lab
echo 'BookNest' | git hash-object -w --stdin
find .git/objects -type f
Output
Initialized empty Git repository in /home/dev/v5-ch2/objects-lab/.git/
25c8a459b6e162ac7b759d609872fcdbfce206f6
.git/objects/25/c8a459b6e162ac7b759d609872fcdbfce206f6

hash-object -w computed the key and wrote the object, filed under a directory named by the first two hex digits so no directory holds millions of files (2). The rest of .git is small: HEAD names the current branch, refs/ holds branch and tag pointers, and config holds repository settings.

How Git turns content into a stored object
How Git turns content into a stored object