Skip to content

Instantly share code, notes, and snippets.

@abiriadev
Created November 9, 2021 03:32
Show Gist options
  • Save abiriadev/d6888f908a97fa28a959c815ad2ec5e1 to your computer and use it in GitHub Desktop.
Save abiriadev/d6888f908a97fa28a959c815ad2ec5e1 to your computer and use it in GitHub Desktop.
converts plain text to a git object
#!/usr/bin/ruby
require 'digest/sha1'
require 'zlib'
content = gets
print "type? (blob): "
type = gets
if type == "" then type = "blob" end
header = "blob #{content.length}\0"
store = header + content
# puts "<#{store}>"
sha1 = Digest::SHA1.hexdigest(store)
puts sha1
zlib_content = Zlib::Deflate.deflate(store)
puts zlib_content
@abiriadev
Copy link
Author

this script referred to chapter 10 of pro git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment