在 Git 中,长哈希和短哈希有什么区别? [英] In Git, what is the difference between long and short hashes?

查看:17
本文介绍了在 Git 中,长哈希和短哈希有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是长的 Git 哈希:

Here is the long Git hash:

提交 c26cf8af130955c5c67cfea96f9532680b963628

commit c26cf8af130955c5c67cfea96f9532680b963628

合并:8654907 37c2a4f

Merge: 8654907 37c2a4f

作者:尼古拉斯

日期:2017 年 4 月 26 日星期三 13:28:22 -0400

Date: Wed Apr 26 13:28:22 2017 -0400

这是简短的:

推荐答案

要详细说明为什么短哈希很有用,以及为什么通常不需要长哈希,这与 Git 存储的方式有关东西.

To elaborate a bit more about why the short hash is useful, and why you often don't need the long hash, it has to do with how Git stores things.

c26cf8af130955c5c67cfea96f9532680b963628 将存储在两个位置之一.它可能在文件 .git/objects/c2/6cf8af130955c5c67cfea96f9532680b963628 中.请注意,前两个字符 c2 构成一个目录,其余字符是文件名.由于当一个目录中有太多文件时,许多文件系统不能很好地运行,这可以防止任何一个目录中包含太多文件,并保持这个小目录数据库的效率.

c26cf8af130955c5c67cfea96f9532680b963628 will be stored in one of two places. It could be in the file .git/objects/c2/6cf8af130955c5c67cfea96f9532680b963628. Note that the first two characters, c2, make up a directory and the rest is the filename. Since many filesystems don't perform well when there's too many files in one directory, this prevents any one directory from having too many files in it and keeps this little directory database efficient.

仅使用短散列 c26cf8a,git 就可以完成与 .git/objects/c2/6cf8a* 等效的操作,而且这很可能是单个文件.由于对象被细分为子目录,因此无需查看太多文件名以检查是否存在多个匹配项.

With just the short hash, c26cf8a, git can do the equivalent of .git/objects/c2/6cf8a* and that's likely to be a single file. Since the objects are subdivided into subdirectories, there's not too many filenames to look through to check if there's more than one match.

c26cf8a 本身就包含了足够多的可能性,16^7 或 2^28 或 268,435,456 使得另一个提交不太可能共享该前缀.

c26cf8a alone contains enough possibilities, 16^7 or 2^28 or 268,435,456 that it's very unlikely another commit will share that prefix.

基本上,Git 使用文件系统本身作为一个简单的键/值存储,它可以查找部分键而无需扫描整个键列表.

Basically, Git uses the filesystem itself as a simple key/value store, and it can look up partial keys without having to scan the whole list of keys.

这是存储对象的一种方式.Git 越来越多地将其对象存储在 packfiles 中.这是一种非常有效的方式来存储文件之间的更改.有时,您的 Git 存储库会检查 .git/objects 中的内容,并将差异存储在 .git/objects/pack/pack- 中.

That's one way to store objects. More and more, Git stores its objects in packfiles. It's a very efficient way to store just the changes between files. From time to time, your Git repository will examine what's in .git/objects and store just the differences in .git/objects/pack/pack-<checksum>.

那是二进制格式,这里不打算深入,反正我自己也看不懂.:)

That's a binary format, I'm not going to get into it here, and I don't understand it myself anyway. :)

这篇关于在 Git 中,长哈希和短哈希有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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