How does SHA generate unique codes for big files in git

后端 未结 3 1941
Happy的楠姐
Happy的楠姐 2020-12-22 15:26

Using Git I don\'t understand how using SHA you can generate just a 40 hexadecimal digit code that can then be mapped to any file which could be hundreds of lines long.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-22 16:06

    The mistake being made is that the SHA code is not used to generate the contents of any files, the contents are stored by Git separately. The SHA code is just used as a key to a commit. The reason commits can't just have keys just numbered from 1 and increasing is because with Git different people can work on different branches of the same project making commits without knowing about each other. When these get merged together we still need commits to have unique keys. The best way of making it so the keys will definitely be unique is using something like SHA which creates a unique code and as others have explained the probability of getting the same key is almost zero.

提交回复
热议问题