git stash pop. Don’t do it!

I love git. I love stash. But if I was a smart person, I would always use git stash apply.

Why?

Because git stash pop loses your most recent stashed changes. If what you popped conflicts with your working tree, the resulting merge will conflict. But the stash is long gone because it was popped onto the working tree. So you have a mess to clean up. Messes are no fun.

The problem is if I pop my stash in the wrong place, it’s no longer stashed. If I’m unlucky I see UU (unmerged, both modified) somewhere. UU means I can’t re-stash my changes. UU is the worst.

If only I’d git stash applyed. Then the changes would still be on the top of stash. I could git reset . without losing them. I could figure out what I did wrong and fix it. At which point git stash apply would work, and I’d be set.

The only downside to apply is it leaves the most recent stashed hunk on top of the stash forever. It pollutes the stash.

But having poped on the wrong branch, I now have to untangle things. The idea of a polluted stash seems a lot better than losing changes.

Used right, git makes it impossible to mess up. Used right, git makes your code immortal. Live on the edge, no consequences! Do crazy shit! If it doesn’t work out—even if it blows up in your face!—a simple git reset . fixes everything. Or git checkout -b oops/this-didnt-go-so-well; git commit -m "but anyway…" isolates the broken code. git checkout - and you’re right where you started, sins forgiven, ready to move on. Whatever didn’t work out is still just an oops branch away.

So apply.

—27 Feb 2014