Skip to content

Instantly share code, notes, and snippets.

@jgn
Created October 4, 2016 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgn/b3dddf091db54b2d719fa02e996dc5a3 to your computer and use it in GitHub Desktop.
Save jgn/b3dddf091db54b2d719fa02e996dc5a3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# from https://stackoverflow.com/posts/24458934/revisions
require 'digest/sha1'
def git_hash(filename)
data = File.read(filename)
Digest::SHA1.hexdigest("blob #{data.bytesize.to_s}\0#{data}")
end
puts git_hash(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment