As far as I understand :
Using CMD :
echo Apple Pie|git hash-object --stdin
return the same think as the following in PowerShell
"Apple Pie" | git hash-object --stdin
That is to say :
157cb7be4778a9cfad23b6fb514e364522167053
@Mofi seems to be right, you can reproduce the CMD result in Powershell using :
'"Apple Pie" ' | git hash-object --stdin
To explain the Mac OS one : To obtain 157cb7be4778a9cfad23b6fb514e364522167053 the real list of chars that is hashed is 'Apple Pie\r\n'
(with carage return line feed), in Mac or linux like command line it's 'Apple Pie\r'
.
If you want to test this : put 'Apple Pie'
in a text file with a cariage return and save it as a Windows text style (CR+LF), and use git hash-object yourfile.txt
. Then save it in Linux style (LF) and test again, you will find your two hashes.
The part about \r\n.
"Apple Pie" | where {$_.length -eq 9}
shows that the string is exactly 9 characters long
For me it's because in your case the pipe is between two PowerShell parts, the pipe transmit an object. When the pipe is between PowerShell and an external EXE then the \r\n are added. Here is a way to test that with a small exe file written in C# :
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)));
}
}
}
}
The result in a PowerShell console is :
"Apple Pie" | .\C_Param.exe
41
70
70
6C
65
20
50
69
65
0D
0A
The result in a CMD console is :
echo "Apple Pie" | .\C_Param.exe
22
41
70
70
6C
65
20
50
69
65
22
20
0D
0A
QED ?