How to recover a dropped stash in Git?

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

    If you didn't close the terminal, just look at the output from git stash pop and you'll have the object ID of the dropped stash. It normally looks like this:

    $ git stash pop
    [...]
    Dropped refs/stash@{0} (2ca03e22256be97f9e40f08e6d6773c7d41dbfd1)
    

    (Note that git stash drop also produces the same line.)

    To get that stash back, just run git branch tmp 2cae03e, and you'll get it as a branch. To convert this to a stash, run:

    git stash apply tmp
    git stash
    

    Having it as a branch also allows you to manipulate it freely; for example, to cherry-pick it or merge it.

提交回复
热议问题