Commit Hashes
What
A commit hash (or “SHA”) is a unique 40-character hexadecimal string that serves as the cryptographic signature and unique identifier of a Git commit.
How
Git uses the SHA-1 hashing algorithm to calculate this signature. Although two developers might commit identical content, their resulting commit hashes will almost always be completely different. A commit hash is derived from several combined factors:
- Content Changes: The exact modifications made to the files.
- Commit Message: The descriptive message written for the commit.
- Author Information: The author’s name and email.
- Timestamp: The exact date and time the commit was created.
- Parent Hash: The hash of the previous (parent) commit.
# Example commit hash:
5ba786fcc93e8092831c01e71444b9baa2228a4f
Why
Because commit hashes are generated mathematically from all of these components, they provide cryptographic integrity. If anyone modifies a single character of code, the commit message, the author, or the timestamp in an existing commit, the resulting hash will change entirely. This guarantees that history cannot be quietly altered or corrupted without breaking the chain of hashes.
Summary
Commit hashes (SHAs) are unique, secure identifiers derived from content, metadata, timestamps, and history, ensuring the absolute integrity of your version timeline.