How to recover a dropped stash in Git?

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

    I liked Aristotle's approach, but didn't like using GITK... as I'm used to using GIT from the command line.

    Instead, I took the dangling commits and output the code to a DIFF file for review in my code editor.

    git show $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' ) > ~/stash_recovery.diff
    

    Now you can load up the resulting diff/txt file (its in your home folder) into your txt editor and see the actual code and resulting SHA.

    Then just use

    git stash apply ad38abbf76e26c803b27a6079348192d32f52219
    

提交回复
热议问题