How does Git compute object IDs (hashes)?

Last updated 6 July 2026

  • Git hashes a header <type> <size>\0 followed by the raw content. The resulting hash is the object ID.

  • It uses SHA-1 historically (40 hex chars), and newer repos can use SHA-256.

  • IDs are content-addressed: identical content deduplicates and corruption is detectable. You can reproduce a hash with git hash-object.

  • https://www.reddit.com/r/cscareerquestions/comments/bxxwfc/what_are_some_behavioral_questions_you_have_been/
  • https://www.reddit.com/r/rails/comments/1shfrbq/3_years_rails_dev_but_failed_basic_interview/
  • https://www.reddit.com/r/cscareerquestions/comments/u7z2xh/how_often_do_developers_look_at_git_trees/
All Git interview questions