What I came here looking for is how to actually get the stash back, regardless of what I have checked out. In particular, I had stashed something, then checked out an older version, then poped it, but the stash was a no-op at that earlier time point, so the stash disappeared; I couldn't just do git stash
to push it back on the stack. This worked for me:
$ git checkout somethingOld$ git stash pop...nothing added to commit but untracked files present (use "git add" to track)Dropped refs/stash@{0} (27f6bd8ba3c4a34f134e12fe69bf69c192f71179)$ git checkout 27f6bd8ba3c$ git reset HEAD^ # Make the working tree differ from the parent.$ git stash # Put the stash back in the stack.Saved working directory and index state WIP on (no branch): c2be516 Some message.HEAD is now at c2be516 Some message.$ git checkout somethingOld # Now we are back where we were.
In retrospect, I should have been using git stash apply
not git stash pop
. I was doing a bisect
and had a little patch that I wanted to apply at every bisect
step. Now I'm doing this:
$ git reset --hard; git bisect good; git stash apply$ # Run tests$ git reset --hard; git bisect bad; git stash applyetc.