Skip to content

Instantly share code, notes, and snippets.

@cbare
Last active August 29, 2015 14:01
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 cbare/2c723ff936d5959cc57e to your computer and use it in GitHub Desktop.
Save cbare/2c723ff936d5959cc57e to your computer and use it in GitHub Desktop.
Find lost stuff in a git repository
############################################################
## 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