0

I executed git stash pop to retrieve some work on my master branch, then accidentally ran git stash pop again which seems to have merged the two stashes but with conflicts. Is there a way to undo the most recent stash without losing the work of the first stash?

anothermh
  • 9,815
  • 3
  • 33
  • 52
DavidM
  • 173
  • 1
  • 9

1 Answers1

0

If the working tree you were on before popping out the two stashes was clean (no pending changes laying around), you could clean up the working tree with git reset --hard. The stash will still hold the second object that you popped out because there were conflicts when popping it out so git doesn't drop it. Try to get the id of the first stash object you popped out from the terminal and run git stash apply <stash-object-id>

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Thanks for responding! By "apply the second one using the id that was provided" do you mean ```git stash apply stash@{0}``` ? Each time I popped it would have been at index 0 – DavidM Dec 14 '18 at 16:07
  • Nope... when you ran `git stash pop`, git provided you with the id of the stash object that it was popping out of the stash. Hmm... actually, now that I think about it, I think the _second_ stash object (the last one you applied) is still in the stash list because there were conflicts when it was applied, right? Can you check with `git stash list`? – eftshift0 Dec 14 '18 at 16:08
  • If the second stash is still on the stash list, then the only thing you need to care about is the _first_ one you applied. Look when you ran the `git stash pop` command and get the id of the stash object that was applied (git tells you that it drops it). – eftshift0 Dec 14 '18 at 16:10
  • Yeah looks like it's still stashed. Can't see the id of the first pop as it's too far back – DavidM Dec 14 '18 at 16:10
  • Then the question is completely different from the one you set up initially: how can I get the id of a stash object that was already dropped if it's lost from my terminal buffer? Check this out: https://stackoverflow.com/questions/89332/how-to-recover-a-dropped-stash-in-git – eftshift0 Dec 14 '18 at 16:12