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

How does Git guarantee history integrity?

IntermediateConceptGit internals: objects, refs and the index
Answer

Each commit ID is a hash over its tree ID and parent IDs, so changing any file, message or ancestor changes every descendant ID. This forms a Merkle DAG. Rewriting history is therefore always creating new commits, never mutating old ones, and git fsck can verify the whole graph.

git fsck --full
All Git & GitHub questions Roadmap: Git & GitHub

More on Git internals: objects, refs and the index