Git 包文件名——摘要是什么?
Git 将各个对象存储在 .git/objects/ab/cdefgh...
中,其中 ab
是 SHA1 摘要的第一个字节。
但是,包文件不遵循相同的命名策略,并且我找不到有关其命名方式的任何文档。有什么见解吗?
Git stores individual objects in .git/objects/ab/cdefgh...
where ab
is the first byte of the SHA1 digest.
However, pack files don't follow the same naming policy, and I can find no documentation on how it is named. Any insights?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
包文件保存在
objects/pack
中,该文件记录在 git 存储库布局。在此目录中,它们以索引文件和包文件本身的形式存储,例如:如何计算这些文件名中的 SHA1sum 在 git-pack-objects 文档(我的重点):
对象名称是包文件中对象的 SHA1 和。
The pack files are kept in
objects/pack
, which is documented in gitrepository layout. Within this directory, they are stored as pairs of an index file and the pack file itself, called, for example:How the SHA1sum in those filenames is calculated is explained in the git-pack-objects documentation (my emphasis):
The object names are the SHA1sums of the objects within the pack file.
答案是“整个包文件的 SHA-1 哈希值减去最后 20 个字节”,或者“最后 20 个字节的十六进制摘要”(两者是等效的)。
文件的最后 20 个字节 是“预告片校验和”,它本身就是一个 整个文件的 SHA-1 哈希(减去最后 20 个字节)。
这是于 2013 年更改(之前它是 中所有哈希值的 SHA-1 总和)文件)。请注意,文档现在只是读取“是基于包内容的哈希值”。作者明确不保证 SHA-1 的计算方式(来自提交日志: “希望这能阻止读者依赖旧的或新的计算。”)。
The answer is either "the SHA-1 hash of the entire pack file, minus the last 20 bytes", or "a hexadecimal digest of the last 20 bytes" (both are equivalent).
The last 20 bytes of the file is the "trailer checksum" which itself is a SHA-1 hash of the entirety of the file (minus the last 20 bytes).
This was changed in 2013 (previously it was the SHA-1 sum of all the hashes in the file). Note that the documentation now simply reads " is a hash based on the pack content". The author explicitly does not guarantee how the SHA-1 is calculated (from the commit log: "Hopefully this will discourage readers from depending on the old or the new calculation.").