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

编程入门 行业动态 更新时间:2024-10-26 22:24:18
本文介绍了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

感谢其他人在此处进行提示.

更多推荐

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

本文发布于:2023-11-30 10:15:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   Powershell   Git   Bash   CMD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!