Skip to content

Commit a69a944

Browse files
authored
Add hash-object to validate ruby hash function
close #1080
1 parent dc3aeba commit a69a944

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

book/10-git-internals/sections/objects.asc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,14 @@ You can calculate the SHA-1 value of a string in Ruby by including the SHA1 dige
381381
=> "bd9dbf5aae1a3862dd1526723246b20206e5fc37"
382382
----
383383

384+
Let's validate the hash with `git hash-object`. It shows that they are identical. Note that `echo` will add a trailing newline character in string, which is not we want in this case. `echo -n` can prevent from adding a trailing newline character.
385+
386+
[source,console]
387+
----
388+
>> $ echo -n "what is up, doc?" | git hash-object --stdin
389+
=> bd9dbf5aae1a3862dd1526723246b20206e5fc37
390+
----
391+
384392
Git compresses the new content with zlib, which you can do in Ruby with the zlib library.
385393
First, you need to require the library and then run `Zlib::Deflate.deflate()` on the content:
386394

0 commit comments

Comments
 (0)