Git & GitHub Interview Question #120
How does Git identify commits and other objects?
Advanced GitHub Actions, Repository Internals, Submodules, LFS & Diagnostic Tools Senior Advanced
Quick Interview Answer
Git identifies stored objects using cryptographic hashes calculated from object content and metadata framing. Users commonly work with abbreviated object IDs when they are unambiguous.
Detailed Explanation
Git identifies stored objects using cryptographic hashes calculated from object content and metadata framing. Users commonly work with abbreviated object IDs when they are unambiguous.
Modern Git supports SHA-256 repositories in addition to the historically dominant SHA-1 object format, but repository compatibility and hosting support should be considered before choosing a non-default object format.
Code Example
git rev-parse HEAD
# Short form
git rev-parse --short HEAD