Skip to content

Commit 894d4e0

Browse files
authored
Update objects.asc
1 parent a69a944 commit 894d4e0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,13 @@ 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.
384+
Let's compare that to the output of `git hash-object`.
385+
Here we use `echo -n` to prevent adding a newline to the input.
385386

386387
[source,console]
387388
----
388-
>> $ echo -n "what is up, doc?" | git hash-object --stdin
389-
=> bd9dbf5aae1a3862dd1526723246b20206e5fc37
389+
$ echo -n "what is up, doc?" | git hash-object --stdin
390+
bd9dbf5aae1a3862dd1526723246b20206e5fc37
390391
----
391392

392393
Git compresses the new content with zlib, which you can do in Ruby with the zlib library.
@@ -417,6 +418,15 @@ Then, open the file with `File.open()` and write out the previously zlib-compres
417418
=> 32
418419
----
419420

421+
Let's check the content of the object using `git cat-file`:
422+
423+
[source,console]
424+
---
425+
$ git cat-file -p bd9dbf5aae1a3862dd1526723246b20206e5fc37
426+
what is up, doc?
427+
---
428+
420429
That's it – you've created a valid Git blob object.
430+
421431
All Git objects are stored the same way, just with different types – instead of the string blob, the header will begin with commit or tree.
422432
Also, although the blob content can be nearly anything, the commit and tree content are very specifically formatted.

0 commit comments

Comments
 (0)