gpt4 book ai didi

bash - Git 哈希对象在 Powershell、CMD 和 Bash 中产生不同的 SHA1?

转载 作者:太空狗 更新时间:2023-10-29 14:27:46 26 4
gpt4 key购买 nike

我认为无论平台如何,SHA1 值都是相同的。我今天遇到了这个,我希望能在这里得到一些澄清。

我的测试字符串是:'Apple Pie'

在 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 key 在不同的环境中非常不同,我不确定如果我将一个项目克隆到我在 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

感谢 that other guy 的提示。

关于bash - Git 哈希对象在 Powershell、CMD 和 Bash 中产生不同的 SHA1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48836583/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com