Skip to content

Instantly share code, notes, and snippets.

@sramam
Created December 20, 2013 15:22
Show Gist options
  • Save sramam/8056254 to your computer and use it in GitHub Desktop.
Save sramam/8056254 to your computer and use it in GitHub Desktop.
Python script that computes the git sha1 value, commandlinized
def git_sha1(fname):
import hashlib
with open(fname, 'r') as f:
data = f.read()
sha1 = hashlib.sha1()
sha1.update("blob %d\0%s" % (len(data), data))
return sha1.hexdigest()
if __name__ == "__main__":
import sys
fname = sys.argv[1]
print git_sha1(fname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment