Interview Prep/Git & GitHub/Git internals: objects, refs and the index

What is the SHA-1 (or SHA-256) hash of an object and how is it computed?

BeginnerConceptGit internals: objects, refs and the index
Answer

The object ID is the hash of a header plus the content: <type> <size>\0<content>. Identical content therefore always yields the same ID, which gives free deduplication and integrity checking. You can reproduce a blob ID by hand.

echo 'hello' | git hash-object --stdin
printf 'blob 6\0hello\n' | sha1sum   # same value
All Git & GitHub questions Roadmap: Git & GitHub

More on Git internals: objects, refs and the index