是否有重复的SHA提交? [英] Is there duplicated SHA commits?

查看:224
本文介绍了是否有重复的SHA提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次提交时,git/hg都会生成一个SHA来在存储库的历史记录中唯一标识该提交.

Every time you make a commit, git/hg generates a SHA to uniquely identify that commit in the repository's history.

假设我要合并两个存储库(我们没有关于哪个存储库的信息). 这就引出了一个问题:如果有人想要提交同一合并后的仓库的特定提交,是否会有重复的SHA哈希值在引起评论时会混淆git?如果不是这样,git会做什么?

Suppose I want to merge two repositories(which we have no information of which ones). This pops the question: if someone wanted a specific commit of that same merged repo, would there be a duplicated SHA hash that would confuse git when getting that comment? And if not so, what would git do?

最终,我想问题还是:全世界每个存储库都有重复的哈希值吗?

Ultimately I guess the question is also: is there duplicated hashes taken every repository of the whole world?

推荐答案

整个世界的每个存储库中都有重复的哈希吗?

Is there duplicated hashes taken every repository of the whole world?

可能是,但这是极不可能.让我在这本书上引用 Git书包含一个非常说明性的示例:

Possibly yes, but that's extremely unlikely. Let me quote the Git book on this one, which contains a very illustrative example:

许多人在某个时候开始担心,由于偶然的原因,他们的存储库中将有两个对象哈希为相同的SHA-1值.那怎么办?

A lot of people become concerned at some point that they will, by random happenstance, have two objects in their repository that hash to the same SHA-1 value. What then?

如果您确实提交了一个哈希值与存储库中先前对象相同的SHA-1值的对象,则Git将在您的Git数据库中看到该先前对象,并假定该对象已被写入.如果您尝试在某个时候再次检出该对象,则将始终获得第一个对象的数据.

[...]

以下是一个示例,可让您大致了解发生SHA-1碰撞的过程.如果地球上所有的65亿人都在编程,并且每一秒钟产生的代码都相当于整个Linux内核历史记录(360万个Git对象)并将其推入一个巨大的Git存储库,则大约需要2年时间直到该存储库中包含足够的对象,才有50%的可能性发生一次SHA-1对象冲突. 更有可能的是,您的编程团队的每个成员在同一晚发生不相关事件时都会受到狼的袭击和杀害.

Here’s an example to give you an idea of what it would take to get a SHA-1 collision. If all 6.5 billion humans on Earth were programming, and every second, each one was producing code that was the equivalent of the entire Linux kernel history (3.6 million Git objects) and pushing it into one enormous Git repository, it would take roughly 2 years until that repository contained enough objects to have a 50% probability of a single SHA-1 object collision. A higher probability exists that every member of your programming team will be attacked and killed by wolves in unrelated incidents on the same night.

简而言之:是的,SHA1碰撞在理论上是可能的,但是从天文学角度讲不可能如此,因此Git根本不会考虑这种情况.

In short: yes, a SHA1 collision is theoretically possible, but so astronomically unlikely that Git simply does not consider this case.

这篇关于是否有重复的SHA提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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