SHA如何为git中的大文件生成唯一的代码 [英] How does SHA generate unique codes for big files in git

查看:118
本文介绍了SHA如何为git中的大文件生成唯一的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Git我不明白如何使用SHA,您只能生成40个十六进制数字代码,然后将其映射到任何可能长达数百行的文件。



我想到它的方式,可以说字符串'1' - > 00 ... 01,字符串'2' - > 00..02,字符串'a34ed..fc' - > a34ed ..fc等等,所以散列图自动返回,那么很明显所有的散列码都会很快用完,任何长度为41个字符的字符串都会重用其中一个代码。



另外我知道大家都知道SHA并不能保证它始终是唯一的,但我不明白它到底如何变得有用。

解决方案

错误在于SHA代码不用于生成任何文件的内容,其内容是由Git单独存储的。 SHA代码仅用作提交的关键。提交的原因不能只有从1开始编号的键,而增加是因为在Git中,不同的人可以在同一个项目的不同分支上进行提交而不必知道彼此。当这些合并到一起时,我们仍然需要提交具有唯一键的提交。使它成为密钥的最好方法绝对是独一无二的,就是使用SHA等创建唯一代码的方法,而其他人已经解释了获得相同密钥的概率几乎为零。

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.

The way I'm thinking of it, lets say the string '1' -> 00...01, the string '2' -> 00..02, the string 'a34ed..fc' -> a34ed..fc etc so the hash map is returning itself then it's clear that all the hash codes get used up very quickly and any string 41 characters long will be reusing one of the codes.

Also I know it's known that SHA doesn't guarantee that it will always be unique but I don't see how it even comes close to being useful.

解决方案

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.

这篇关于SHA如何为git中的大文件生成唯一的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆