I am trying to apply changes I stashed earlier with git stash pop
and get the message:
Cannot apply to a dirty working tree, please stage your changes
Any suggestion on how to deal with that?
I am trying to apply changes I stashed earlier with git stash pop
and get the message:
Cannot apply to a dirty working tree, please stage your changes
Any suggestion on how to deal with that?
I was unable to get most of these to work; for some reason it always thinks I have local changes to a file. I can't apply a stash, patches won't apply,
checkout
andreset --hard
fail. What finally worked was saving the stash as a branch withgit stash branch tempbranchname
, and then doing a normal branch merge:git checkout master
andgit merge tempbranchname
. From http://git-scm.com/book/en/Git-Tools-Stashing :I do it in this way:
and then (optionaly):
When I have to apply stashed changes to a dirty working copy, e.g. pop more than one changeset from the stash, I use the following:
Basically it
I wonder why there is no
-f
(force) option forgit stash pop
which should exactly behave like the one-liner above.In the meantime you might want to add this one-liner as a git alias:
Thanks to @SamHasler for pointing out the
-3
parameter which allows to resolve conflicts directly via 3-way merge.You have files that have been modified but not committed. Either:
or, if you want to save your changes:
You can apply a stash to a "dirty" tree by doing a
git add
to stage any changes you've made, thus cleaning up the tree. Then you cangit stash pop
and apply the stashed changes, no problem.None of these answers actually work if you find yourself in this situation as I did today. Regardless of how many
git reset --hard
's I did, it got me nowhere. My answer (not official by any means was):git reflog --all