为什么Git使用*压缩*对象的SHA1而不是原始对象的SHA1? [英] Why does Git use the SHA1 of the *compressed* objects rather than the SHA1 of the original objects?

查看:727
本文介绍了为什么Git使用*压缩*对象的SHA1而不是原始对象的SHA1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是好奇为什么这个选择是 - 它基本上排除了改变Git使用的压缩算法 - 因为它不使用原始blob的SHA1。也许在这里有一些效率的考虑。也许ZLIB在压缩文件比SHA1算法在创建哈希更快,因此压缩之前的哈希更快?

I'm just curious as to why this choice was made - it basically rules out changing the compression algorithm used by Git - because it doesn't use the SHA1 of the raw blobs. Perhaps there is some efficiency consideration here. Maybe ZLIB is faster at compressing a file than the SHA1 algorithm is at creating the hash, so therefore compressing before hashing is faster?

这是一个指向原始Git READMEby Linus的链接: http://git.kernel.org/?p=git​​/git.git;a=blob;f=README;h=27577f76849c09d3405397244eb3d8ae1d11b0f3;hb= e83c5163316f89bfbde7d9ab23ca2e25604af290

Here is a link to the original Git READMEby Linus: http://git.kernel.org/?p=git/git.git;a=blob;f=README;h=27577f76849c09d3405397244eb3d8ae1d11b0f3;hb=e83c5163316f89bfbde7d9ab23ca2e25604af290

和这里是relavent段落:

And here is the relavent paragraph:

有以下几种对象的的内容可寻址集合
的数据库。他们都在瘪与zlib的,并与他们的类型的标签,以及有关数据大小信息开始。该SHA1哈希总是的压缩的哈希对象,而不是原始对象。

"There are several kinds of objects in the content-addressable collection database. They are all in deflated with zlib, and start off with a tag of their type, and size information about the data. The SHA1 hash is always the hash of the compressed object, not the original one."

推荐答案

> README,当Git启动时。从那时起,它已被更改,以便SHA1被压缩前计算。

Like you said, it is the original README, when Git was started. Since then, it has been changed so that the SHA1 is computed before compressing.

这是值得注意的是,所使用的SHA-1散列命名对象
是原始数据加上此头的哈希,因此sha1sum文件
与文件的对象名不匹配。 (历史记录:在dait的
的git的年龄的哈希是压缩对象的SHA-1。

It’s worth noting that the SHA-1 hash that is used to name the object is the hash of the original data plus this header, so 'sha1sum' file does not match the object name for file. (Historical note: in the dawn of the age of git the hash was the SHA-1 of the compressed object.)

http://schacon.github.com/git/user -manual.html#object-details

这篇关于为什么Git使用*压缩*对象的SHA1而不是原始对象的SHA1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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