git 如何计算文件哈希? [英] How does git compute file hashes?

查看:23
本文介绍了git 如何计算文件哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储在树对象中的 SHA1 哈希值(由 git ls-tree 返回)与文件内容的 SHA1 哈希值(由 sha1sum 返回)不匹配

The SHA1 hashes stored in the tree objects (as returned by git ls-tree) do not match the SHA1 hashes of the file content (as returned by sha1sum)

$ git cat-file blob 4716ca912495c805b94a88ef6dc3fb4aff46bf3c | sha1sum
de20247992af0f949ae8df4fa9a37e4a03d7063e  -

git 如何计算文件哈希?是否在计算散列之前压缩内容?

How does git compute file hashes? Does it compress the content before computing the hash?

推荐答案

Git 以blob"作为对象的前缀,后跟长度(作为人类可读的整数),后跟一个 NUL 字符

Git prefixes the object with "blob ", followed by the length (as a human-readable integer), followed by a NUL character

$ echo -e 'blob 14Hello, World!'|沙苏姆8ab686eafeb1f44702738c8b0f24f2567c36da6d

来源:http://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html

这篇关于git 如何计算文件哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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