Is there any way to search through old commits in a #git repository for something that accidentally got deleted?
@woozle git log --follow <filename>
as long as it was in your history you'll see all commits where that file's changed
@woozle here's a stack overflow for this that i've searched for a million times and still have troubles finding https://stackoverflow.com/questions/3701404/list-all-commits-for-a-specific-file/20672255
@vahnj What if I didn't know which file the missing definition was in, though? Is there a way to search for, say, the last occurrence of a piece of text, in any file?
@woozle you know a line from the file?
yeah, you can git diff between commits, and even do relative commits!
try something like this:
git diff HEAD^^^^^^^^^^^^^^^^^^^^
this'll pull out a ton of commits to diff against the head pointer of whatever branch you're on. then you can use text search against the snippet you have. that will help you pull apart the file, and then you can find the commit where you deleted it from there!
So, it's academic at this point because I found a backup that was old enough to include the missing piece, but...
...before that point, what I had was an invocation of a class that wasn't defined anywhere, and that's all I knew.
So I'd have needed to be able to search for "classname" across all files, including deleted, starting with the most recent commit and working backwards.
@woozle @er1n (he says with a facetious laugh that reveals embarrassment)