Last active
August 29, 2015 14:03
-
-
Save leifericf/83f69fb1d631fcf55322 to your computer and use it in GitHub Desktop.
Generate Git file (aka "blob") hash, without using Git.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'digest/sha1' | |
def git_hash(file) | |
data = File.read(file) | |
size = data.bytesize.to_s | |
Digest::SHA1.hexdigest('blob ' + size + "\0" + data) # Git's hashing algorithm | |
end | |
puts git_hash(ARGV[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment