Since Git is distributed there is never one "ground truth" repository that can decide what commit will have what id. Also, repositories cannot communicate what ids are taken or not. Hence, every single Git installation should make sure to minimise the risk of having a collision (two commits having the same id).
To achieve that, Git is using a hashing algorithm called SHA1 to calculate the commit ids. Each commit id consists of 160 bit of data, meaning you can have 2^160 possible combinations (approx. a 1 with 50 zeroes).
Using a hash function does not guarantee uniqueness but minimises the probability of a collision since hashing algorithms are specifically designed to do ensure that.
SVN on the other hand has a central repository and can therefore use consecutive integer numbers.
Git itself doesn't have a method of handling collisions: If you pull a set of commits with one or more collisions, Git will simply ignore the colliding commit; leaving the original one in place.
Also: Using a hashing algorithm doesn't only solve the problem of commit ids but is also a security measure: Since all data for a commit (diff, author, date and SHA1 of the previous commit) are used to calculate the hash it is impossible to change patches afterwards without having to change every single hash since then