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
More on Git internals: objects, refs and the index
What are the four object types in Git's object database?BeginnerIs Git a snapshot system or a diff system?BeginnerWhere does Git store objects on disk, and what are loose objects versus packfiles?IntermediateWhat exactly is a branch, and what does creating one cost?IntermediateWhat is HEAD?BeginnerWhat is a detached HEAD and how do you recover work done in it?Intermediate