Skip to content

Instantly share code, notes, and snippets.

@kejinlu
Created May 14, 2013 04:40
Show Gist options
  • Save kejinlu/5573737 to your computer and use it in GitHub Desktop.
Save kejinlu/5573737 to your computer and use it in GitHub Desktop.
Verify git object with python!
#!/usr/bin/python
# -*- coding: utf-8 -*-
import zlib,os,sys,hashlib
reload(sys)
sys.setdefaultencoding('utf8')
if len(sys.argv) < 2:
print "Need the path of git object!"
exit()
filePath = sys.argv[1]
fp = open(os.path.expanduser(filePath))
str = fp.read()
fp.close()
str = zlib.decompress(str)
print str
gitsha1 = hashlib.sha1()
gitsha1.update(str)
print gitsha1.hexdigest()
@kejinlu
Copy link
Author

kejinlu commented May 14, 2013

python gitverify.py ~/Projects/mygit/.git/objects/61/f26c0d181a3f3ae6c0db23c775856760040502

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