Jim Clay
Jim Clay

Reputation: 1003

Undo "git stash --patch"

I executed "git stash -p" (equivalent to "git stash --patch") which successfully stashed part of the changes that I had made to the code. When I tried to run "git stash pop" it gave me the following message:

error: Your local changes to the following files would be overwritten by merge:

[list of files]

Please, commit your changes or stash them before you can merge.

Aborting

How can I get all of my changes back? This question appears to have a method (haven't tried it yet), but I was hoping for something cleaner and simpler.

Upvotes: 3

Views: 233

Answers (1)

Arne L.
Arne L.

Reputation: 2320

I just into the same problem. Here is what I did:

$ git stash --patch
# now you have a 'partial' stash
#
# commit all changes in your working tree
$ git add .
$ git commit -m TEMP
# pop the stash
$ git stash pop
# now your stashed changes have been applied successfully
#
# reset your working tree to the original state
$ git reset --soft HEAD^^
# optionally reset your index
$ git reset .

This resets your working tree to the state before the git stash. The changes to your index will we lost.

Upvotes: 3

Related Questions