Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aborting a stash pop in Git

Tags:

git

git-stash

I popped a stash and there was a merge conflict. Unlike the question that is listed as a duplicate, I already had some uncommitted changes in the directory which I wanted to keep. I don't just want to make the merge conflict disappear, but also to get my directory back to the state it was before the pop.

I tried git merge --abort, but git claimed no merge was in progress. Is there an easy way to abort a pop without destroying the changes I originally had in the directory?

like image 364
Casebash Avatar asked Dec 15 '11 05:12

Casebash


People also ask

Can I abort a git stash pop?

You can use git reset to unstage your changes if you like. Given that your original git stash apply failed I assume the reverse might also fail since some of the things it wants to undo did not get done.

How do I pop off stash?

To pop Git stashes, simply use the “git stash pop” command and specify the stash index you want to pop. See the difference in the last line of the example? The stash was dropped and removed from the stack.


2 Answers

My use case: just tried popping onto the wrong branch and got conflicts. All I need is to undo the pop but keep it in the stash list so I can pop it out on the correct branch. I did this:

git reset HEAD --hard git checkout my_correct_branch git stash pop 

Easy.

like image 173
jmoz Avatar answered Oct 10 '22 17:10

jmoz


Simple one liner

I have always used

git reset --merge

I can't remember it ever failing.


Note: git reset --merge will discard any staged changes

like image 40
Kenn Sebesta Avatar answered Oct 10 '22 19:10

Kenn Sebesta