我认为无论平台如何,SHA1 值都是相同的。我今天遇到了这个问题,希望我能在这里得到一些澄清。
我的测试字符串是:'Apple Pie'
In Bash:
echo 'Apple Pie' | git hash-object --stdin
23991897e13e47ed0adb91a0082c31c82fe0cbe5
在 CMD(Windows 10)中:
echo 'Apple Pie' | git hash-object --stdin
f554ff1fdde0e3c2ca9f67849791456302b5c12b
在 Powershell 5.0 (Windows 10) 中:
echo 'Apple Pie' | git hash-object --stdin
157cb7be4778a9cfad23b6fb514e364522167053
我现在很困惑 git 在这里是如何工作的,因为文件内容的 sha1 密钥在不同的环境中非常不同,我不确定如果我将一个项目克隆到我在 Powershell 中构建的 Linux 机器中是否会起作用?一般来说,这种行为在 git 或 SHA1 中是预期的吗?
毫无疑问,这三个值都是正确的。你所看到的是echo
三个命令解释器中不是同一个命令!
$ printf 'Apple Pie\n' | git hash-object --stdin
23991897e13e47ed0adb91a0082c31c82fe0cbe5
$ printf 'Apple Pie\r\n' | git hash-object --stdin
157cb7be4778a9cfad23b6fb514e364522167053
编辑:可以通过以下方式在 bash 中模拟 Windows 10 CMD(以获得相同的哈希值):
$ printf "'Apple Pie' \r\n" | git hash-object --stdin
f554ff1fdde0e3c2ca9f67849791456302b5c12b
谢谢另一个人 https://stackoverflow.com/questions/48836583/git-hash-object-is-yielding-different-sha1-in-powershell-cmd-and-bash/48836657?noredirect=1#comment84678708_48836657这里的提示。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)