How to recover a dropped stash in Git?

前端 未结 19 1753
别跟我提以往
别跟我提以往 2020-11-22 01:42

I frequently use git stash and git stash pop to save and restore changes in my working tree. Yesterday I had some changes in my working tree that I

19条回答
  •  梦谈多话
    2020-11-22 02:08

    I couldn't get any of the answers to work on Windows in a simple command window (Windows 7 in my case). awk, grep and Select-string weren't recognized as commands. So I tried a different approach:

    • first run: git fsck --unreachable | findstr "commit"
    • copy the output to notepad
    • find replace "unreachable commit" with start cmd /k git show

    will look something like this:

    start cmd /k git show 8506d235f935b92df65d58e7d75e9441220537a4 start cmd /k git show 44078733e1b36962571019126243782421fcd8ae start cmd /k git show ec09069ec893db4ec1901f94eefc8dc606b1dbf1 start cmd /k git show d00aab9198e8b81d052d90720165e48b287c302e

    • save as a .bat file and run it
    • the script will open a bunch of command windows, showing each commit
    • if you found the one you're looking for, run: git stash apply (your hash)

    may not be the best solution, but worked for me

提交回复
热议问题