Warm-up · from “Snapshots versus changes”
What does a commit reference for its snapshot?
What does a commit reference for its snapshot?
No notes: write what you remember, then check. Recalling before reading is what makes it stick.
The problem
Two filenames hold identical bytes. Can Git identify them as the same stored content without knowing either filename?
After this lesson you can
Explain content addressing.
Inspect a loose blob.
Distinguish object identity from filename.
Key terms
Full glossarySay what each term means, then open it to check.
Object ID · new in this lesson
Hash-based identity of a serialized Git object.
Blob · new in this lesson
Object storing file contents without a filename.
Visual mental model
- Raw bytes
- Header + bytestype, size, NUL, then content
- Hash ID
- Compressed loose object
Build the mental model
A blob holds file contents, not a filename or timestamps. Git computes its object ID from a header and payload: for a blob, the bytes are blob, a space, the decimal payload size, a NUL byte, then the content. With SHA-1, the resulting ID has 40 hexadecimal characters. SHA-256 repositories use 64. This book uses SHA-1 for reproducible labs.
Computed in your browser: SHA-1 of "blob <size>\0<bytes>", identical to git hash-object.
Under the hood
Loose objects are compressed with zlib and stored under the first two hex characters of the ID, followed by the rest as the filename. Git may store the same logical object in a pack instead. Equal bytes of the same object type in the same hash format produce equal IDs; different content generally produces different IDs. Hash collisions are possible in principle, and Git includes collision protections for SHA-1.
Common mistake · important nuance
Git hashes the object header plus content, not just the raw file. Filters may transform file contents during staging; these labs use simple text with no filters.