Why Git commits use 40-character hexadecimal strings
Every commit, tree, and blob recorded in Git is indexed by a 40-character hexadecimal string representing a 160-bit SHA-1 hash. Instead of storing file versions sequentially like older version control tools, Linus Torvalds designed Git as a content-addressable filesystem. The hash is computed from the uncompressed file data and commit metadata. Two identical files, regardless of their filenames or paths, share the exact same hash and take up zero duplicate storage space.
The Concept of Content-Addressable Storage
Traditional operating systems locate files through hierarchical paths and file tables. An operating system maps a human-readable name, such as a document title inside a folder, to an arbitrary location or inode on a storage device. If that file is modified, its location on disk may update or remain in place, but its name and file path stay constant while the underlying data changes. Version control systems prior to Git frequently mirrored this logic, organizing revisions as sequences of file diffs tracked along file paths across linear revisions.
When Linus Torvalds designed Git in 2005 to manage Linux kernel development, he inverted this convention. Git was architected not as a standard file tracker, but as a content-addressable filesystem layered beneath a set of version control tools. In a content-addressable system, data is not retrieved by asking where it lives or what name it was given. Instead, the storage address of any piece of data is derived mathematically from the exact bytes of the data itself.
This architectural decision means that storage keys and file contents are fundamentally inseparable. If the content changes by even a single bit, its address changes completely. If two files anywhere across an entire project contain the exact same byte sequence, they produce identical addresses, allowing the underlying storage engine to handle storage, retrieval, and deduplication through purely mathematical means.
Constructing the 40-Character Hexadecimal Hash
The string identifying every Git object is a 40-character hexadecimal representation of a 160-bit SHA-1 cryptographic checksum. A 160-bit number consists of 20 bytes. When represented in human-readable text, each byte is written as two hexadecimal characters covering the digits zero through nine and the lowercase letters a through f, resulting in a fixed 40-character fingerprint.