Skip to content

Instantly share code, notes, and snippets.

@dirkjot
Created December 5, 2015 02:26
Show Gist options
  • Save dirkjot/073ffac502567e32f7ad to your computer and use it in GitHub Desktop.
Save dirkjot/073ffac502567e32f7ad to your computer and use it in GitHub Desktop.
#!/bin/sh
# inspired by this SO answer by Uwe Geuder
# http://stackoverflow.com/questions/277546/can-i-use-git-to-search-for-matching-filenames-in-a-repository/6960138#6960138
# this will create one 'foundin-$rev.txt' file for each of your revisions, feel free to delete them after use
# ADJUST THIS TO YOUR NEEDS:
SEARCHTERM="file-that-was-long-lost.txt"
allrevs=$(git rev-list --all)
# well, nearly all revs, we could still check the log if we have
# dangling commits and we could include the index to be perfect...
for rev in $allrevs
do
echo "Working on $rev"
git ls-tree --full-tree -r $rev | grep $SEARCHTERM > foundin-$rev.txt
done
grep $SEARCHTERM foundin-*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment