0

I accidentally run git checkout . and lost the changes I made on my local repo.

I remember that once I had those changes stashed but I used git stash pop to retrieve them (sadly, I didn't know about git stash apply at the time), and now I can not find these changes on my stash.

I searched on SO but most of the answers were for git stash apply, or told me to retrieve the SHA-1 outputted after the git stash pop, but I don't have that information.

Is there any way to recover my changes?

Guilherme Lemmi
  • 3,271
  • 7
  • 30
  • 30
  • 2
    When you call `git stash pop`, you apply the changes for the stash at the top of the stack _and_ you also remove/pop those changes from the stash. So, if you really used pop, then the changes are probably gone forever. Moving forward, if there be _any_ chance that you would need to use the changes more than once, then _always_ use `git stash apply`. – Tim Biegeleisen Jun 21 '19 at 01:25
  • 2
    If the terminal where the pop was run is still open, the id of that stash object (reported on the execution) can still be used with `git stash apply` – eftshift0 Jun 21 '19 at 01:27
  • Unfortunately, some days passed between the `git stash pop` and the `git checkout .`, the terminal from pop was not open anymore. I was thinking that maybe some reflog magic could save me but I guess I'll just have to think on my changes and write them again. :( – Guilherme Lemmi Jun 21 '19 at 01:33
  • 1
    https://stackoverflow.com/questions/89332/how-to-recover-a-dropped-stash-in-git – Ry- Jun 21 '19 at 01:35
  • Unfortunately, `git stash pop` removes the reflog entry—in fact, the pushed stash stack is nothing *but* reflog entries. – torek Jun 21 '19 at 01:47
  • 1
    Amazing! executing command `git fsck --no-reflog | select-string 'dangling commit' | foreach { $bits = $_ -split ' '; echo $bits[2];}` shown the stash SHA-1! Then I could retrieve it with `git stash apply {SHA}` – Guilherme Lemmi Jun 21 '19 at 02:10

0 Answers0