diff --git a/book/10-git-internals/sections/objects.asc b/book/10-git-internals/sections/objects.asc index f49842fa9..ec076c7e3 100644 --- a/book/10-git-internals/sections/objects.asc +++ b/book/10-git-internals/sections/objects.asc @@ -381,6 +381,15 @@ You can calculate the SHA-1 value of a string in Ruby by including the SHA1 dige => "bd9dbf5aae1a3862dd1526723246b20206e5fc37" ---- +Let's compare that to the output of `git hash-object`. +Here we use `echo -n` to prevent adding a newline to the input. + +[source,console] +---- +$ echo -n "what is up, doc?" | git hash-object --stdin +bd9dbf5aae1a3862dd1526723246b20206e5fc37 +---- + Git compresses the new content with zlib, which you can do in Ruby with the zlib library. First, you need to require the library and then run `Zlib::Deflate.deflate()` on the content: @@ -409,6 +418,15 @@ Then, open the file with `File.open()` and write out the previously zlib-compres => 32 ---- +Let's check the content of the object using `git cat-file`: + +[source,console] +--- +$ git cat-file -p bd9dbf5aae1a3862dd1526723246b20206e5fc37 +what is up, doc? +--- + That's it – you've created a valid Git blob object. + 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. Also, although the blob content can be nearly anything, the commit and tree content are very specifically formatted.