Find lost stuff in a git repository
This file contains 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
############################################################ | |
## Find lost stuff in a git repository ## | |
## ## | |
## run in the root of your git repo ## | |
## Usage: python grep_git_objects.py <target> ## | |
############################################################ | |
import os | |
import sys | |
import subprocess | |
if len(sys.argv) < 2: | |
print "Usage: python grep_git_objects.py <target>" | |
sys.exit() | |
target = sys.argv[1] | |
hashes = [] | |
for i in range(0,256): | |
dirname = ".git/objects/%02x" % i | |
#print dirname | |
for filename in os.listdir(dirname): | |
h = "%02x%s" % (i, filename) | |
hashes.append(h) | |
cmd = "git cat-file -p %s" % h | |
output = subprocess.check_output(cmd.split(' ')) | |
if target in output: | |
print "found in object: ", h | |
print output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment