Git uses SHA-1 for the user to refer a commit.
Subversion (SVN) and Mercurial (hg) use an incremental number.
Why did the Git team make that design decision of using SHA-1 instead of something more descriptive?
GIT strongly relies on SHA-1 for the identification and integrity checking of all file objects and commits. It is essentially possible to create two GIT repositories with the same head commit hash and different contents, say a benign source code and a backdoored one.
At its core, the Git version control system is a content addressable filesystem. It uses the SHA-1 hash function to name content.
"SHA" stands for Simple Hashing Algorithm. The checksum is the result of combining all the changes in the commit and feeding them to an algorithm that generates these 40-character strings. A checksum uniquely identifies a commit.
Git uses SHA-1-generated hashes to identify revisions and protect code against corruption. Unfortunately, SHA-1's foundation has been weakened by a series of vulnerabilities that have been found in the codebase, and is considered broken.
Mercurial (hg) also uses SHA1 hashes. It just also tries to get revision numbers out of the commit history. However, these revisions are only valid in one repository. If you watch another repo, these revisions are not guaranteed to match.
As to why git and mercurial use hashes: both have a non-linear commit history. because both are distributed, people can work on the same code basis in their local repositories without having to synchronize to a central authority (as required by SVN and CVS). Now if people commit their stuff locally and merge them later, you will have a hard time to come up with a consistent schema to form linearly increasing integer revisions. And even if you could, you would still get different result between different repos.
In the end, it's all because of the distributed nature. It is a simple way to come up with rather unique identifiers to commits. And as a side-product you can also encode the complete history towards a single commit into the hash. Which means, even if you have the same diff in a commit, you probably will get different SHA1 hashes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With