6

I have some files I'm looking for, but that I don't know where they are located in my git repository (both in space and time). I also speculate it is possible that both the files and the branch in which they reside might be deleted.

How could I list every file ever in existence in the whole git repository? I know deleted files / branches could pretty well have already been garbage collected, and well, there's nothing to do about it than to pray it didn't happen already.

Thanks!

1 Answer 1

3

This is a bit crazy, but it might do what you want:

#!/bin/sh content="$@" for hash in $({ git rev-list --objects --all git rev-list --objects -g --no-walk --all git rev-list --objects --no-walk \ $(git fsck --unreachable | grep '^unreachable commit' | cut -d' ' -f3) git fsck --unreachable | grep "^unreachable blob" | cut -d' ' -f3 } 2> /dev/null | cut -d' ' -f1 | sort | uniq); do if git cat-file blob $hash 2> /dev/null | grep -i $content > /dev/null ; then echo $hash fi done 

I tried to get absolutely every blob accessible, and look for a specific content in each of them.

You'll be able to do a git cat-file -p hash on each of the generated hashes and might find your lost file.


On a side note, I'm surprised to not see any nice way to list absolutely every object available in the repository. I was thinking of unpacking everything and go from there, that could be a better solution too.


Resources:

Related topics:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.