Git哈希对象在Powershell,CMD和Bash中产生不同的SHA1? [英] Git hash-object is yielding different SHA1 in Powershell, CMD and Bash?

查看:123
本文介绍了Git哈希对象在Powershell,CMD和Bash中产生不同的SHA1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I thought SHA1 value would be same regardless of the platform. And I encountered this today and I hope I can get some clarification here.

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

在Bash中:

echo 'Apple Pie' | git hash-object --stdin
23991897e13e47ed0adb91a0082c31c82fe0cbe5

在CMD中(Windows 10):

In CMD (Windows 10):

echo 'Apple Pie' | git hash-object --stdin
f554ff1fdde0e3c2ca9f67849791456302b5c12b

在Powershell 5.0(Windows 10)中:

In Powershell 5.0 (Windows 10):

echo 'Apple Pie' | git hash-object --stdin
157cb7be4778a9cfad23b6fb514e364522167053

我现在对git的工作方式感到困惑,因为文件内容的sha1键在不同的环境中是非常不同的,而且我不确定如果将一个项目克隆到Powershell内置的linux机器中是否可以正常工作?通常在git或SHA1中会出现这种现象吗?

I am now confused how git works here since the sha1 key for file contents are very different in different environment and I am not sure if it would work if I clone one project into my linux machine which was built in Powershell? Is this behavior expected in git or in SHA1 in general?

推荐答案

所有三个值无疑都是正确的.您将看到在三个命令解释器中echo不是同一命令!

All three values are no doubt correct. What you are seeing is that echo is not the same command in the three command interpreters!

$ printf 'Apple Pie\n' | git hash-object --stdin
23991897e13e47ed0adb91a0082c31c82fe0cbe5
$ printf 'Apple Pie\r\n' | git hash-object --stdin
157cb7be4778a9cfad23b6fb514e364522167053

Windows 10 CMD可以通过以下方式在bash中仿真(以获取相同的哈希值):

Windows 10 CMD can be emulated in bash (to get the same hash) via:

$ printf "'Apple Pie' \r\n" | git hash-object --stdin
f554ff1fdde0e3c2ca9f67849791456302b5c12b

感谢 查看全文

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