How to recover a dropped stash in Git?

前端 未结 19 1708
别跟我提以往
别跟我提以往 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 01:51

    My favorite is this one-liner:

    git log --oneline  $( git fsck --no-reflogs | awk '/dangling commit/ {print $3}' )
    

    This is basically the same idea as this answer but much shorter. Of course, you can still add --graph to get a tree-like display.

    When you have found the commit in the list, apply with

    git stash apply THE_COMMIT_HASH_FOUND
    

    For me, using --no-reflogs did reveal the lost stash entry, but --unreachable (as found in many other answers) did not.

    Run it on git bash when you are under Windows.

    Credits: The details of the above commands are taken from https://gist.github.com/joseluisq/7f0f1402f05c45bac10814a9e38f81bf

提交回复
热议问题