0

So there is this script in my project called tools/install-wamp-router.js that's broken. The thing is, I know the problem and I know I fixed it before, and I also don't want to fix it again. I'm pretty sure I committed the changes or stashed them and that the file is lost somewhere in my local repo.

I have tons of branches and 36 stashes on my machine. I'd like to find this lost revision of the file. My idea is to search ALL branches and stashes for different versions of the file and output the commit hash and commit message for each hit (as well as in which stash it is maybe).

I got as far as the following command, which only checks branches, and I didn't find what I was looking for.

git log --follow --all -- tools/install-wamp-router.js

Please help!

And yes this is easier than actually fixing the file, it involved a lot of trial and error and making sure it ran on both linux and windows.

GregRos
  • 8,667
  • 3
  • 37
  • 63
  • “which only checks branches”—`git log --all` also checks other refs for me, like `refs/notes/commits`. You mention the stash. Could you have _dropped_ the stash? If so it will be unreachable and you will need this https://stackoverflow.com/questions/89332/how-do-i-recover-a-dropped-stash-in-git – Guildenstern May 04 '23 at 16:22
  • @Guildenstern I am normally terrified of dropping stashes, but it could've happened. Other things could also have happened. Maybe I just don't remember right. – GregRos May 04 '23 at 16:29
  • This should work for the stashes: `git stash list --stat` – TTT May 04 '23 at 16:45
  • If you are vigilant/terrified of dropping stashes then it shouldn’t take long to check if any of them might contain this file https://pastebin.com/kJ6vBVsA – Guildenstern May 04 '23 at 17:09
  • Yet another reason to [**stop using stash**](https://stackoverflow.com/a/27117335/23118) and instead use proper [**temporary commits**](https://stackoverflow.com/a/75010635/23118). Temporary commits: guaranteed to be covered with `git log`, stash: maybe, who knows (could change over time with git versions as well)? – hlovdal May 05 '23 at 09:11

1 Answers1

1

If you know a line of code (in the current, bugged version of your file) that was involved in the fix, you can try to use one of the pickaxe options -G or -S :

# -G expects a regexp, you will have to escape the regex special characters
git log --all --reflog -G 'a_line\.of_code\(that, got, changed\)'

# by default, -S expects a plain string:
git log --all --reflog -S 'a_line.of_code(that, got, changed)'

You will get the commits for which the diff mentions that line at all (-G) or where the number of times this line appeared changed (-S).

LeGEC
  • 46,477
  • 5
  • 57
  • 104