据我所理解 :
使用 CMD :
echo Apple Pie|git hash-object --stdin
在 PowerShell 中返回与以下相同的想法
"Apple Pie" | git hash-object --stdin
也就是说 :
157cb7be4778a9cfad23b6fb514e364522167053
@Mofi 似乎是对的,您可以使用以下命令在 Powershell 中重现 CMD 结果:
'"Apple Pie" ' | git hash-object --stdin
解释 Mac OS 之一:要获得 157cb7be4778a9cfad23b6fb514e364522167053,真正的散列字符列表是'Apple Pie\r\n'
(带有回车换行符),在 Mac 或 linux 之类的命令行中是'Apple Pie\r'
.
如果您想对此进行测试:放入'Apple Pie'
一个带有回车符的文本文件并将其保存为 Windows 文本样式 (CR+LF),然后使用git hash-object yourfile.txt
. 然后将其保存为 Linux 风格(LF)并再次测试,您将找到您的两个哈希值。
关于\r\n的部分。
"Apple Pie" | where {$_.length -eq 9}
表明字符串正好是 9 个字符长
对我来说,这是因为在您的情况下,管道位于两个 PowerShell 部分之间,管道传输一个对象。当管道位于 PowerShell 和外部 EXE 之间时,将添加 \r\n。这是一种使用 C# 编写的小型 exe 文件进行测试的方法:
using System;
namespace C_Param
{
class Program
{
static void Main(string[] args)
{
string line = Console.In.ReadToEnd();
foreach (char character in line){
Console.WriteLine(String.Format("{0:X2}", Convert.ToByte(character)));
}
}
}
}
PowerShell 控制台中的结果是:
"Apple Pie" | .\C_Param.exe
41
70
70
6C
65
20
50
69
65
0D
0A
CMD 控制台中的结果是:
echo "Apple Pie" | .\C_Param.exe
22
41
70
70
6C
65
20
50
69
65
22
20
0D
0A
QED ?