Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在git book 的这一部分,有存储 git 对象的 ruby 代码。但是,它生成的键与 git hash-object 命令生成的键不匹配(在本章开头进行了解释)
$ echo 'what is up, doc?' | git hash-object --stdin 7108f7ecb345ee9d0084193f147cdad4d2998293
虽然本章中的示例代码产生:bd9dbf5aae1a3862dd1526723246b20206e5fc37
bd9dbf5aae1a3862dd1526723246b20206e5fc37
我错过了什么?谢谢!
echo自动将 a 添加\n到其输出中,因此您实际上是在散列 string "what is up, doc?\n"。您可以通过传递-n给来抑制它echo:
echo
\n
"what is up, doc?\n"
-n
echo -n 'what is up, doc?' | git hash-object --stdin
这给出了预期的输出。