I did a git stash pop
and ended up with merge conflicts. I removed the files from the file system and did a git checkout
as shown below, but it thinks the files are still unmerged. I then tried replacing the files and doing a git checkout
again and same result. I event tried forcing it with -f
flag. Any help would be appreciated!
chirag-patels-macbook-pro:haloror patelc75$ git status
app/views/layouts/_choose_patient.html.erb: needs merge
app/views/layouts/_links.html.erb: needs merge
# On branch prod-temp
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: db/schema.rb
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# unmerged: app/views/layouts/_choose_patient.html.erb
# unmerged: app/views/layouts/_links.html.erb
chirag-patels-macbook-pro:haloror patelc75$ git checkout app/views/layouts/_choose_patient.html.erb
error: path 'app/views/layouts/_choose_patient.html.erb' is unmerged
chirag-patels-macbook-pro:haloror patelc75$ git checkout -f app/views/layouts/_choose_patient.html.erb
warning: path 'app/views/layouts/_choose_patient.html.erb' is unmerged
See man git merge (HOW TO RESOLVE CONFLICTS):
And under TRUE MERGE (to see what 2. and 3. refers to):
So: use
git reset --hard
if you want to remove the stash changes from your working tree, orgit reset
if you want to just clean up the index and leave the conflicts in your working tree to merge by hand.Under man git stash (OPTIONS, pop) you can read in addition:
I had a similar thing happen to me. I didn't want to stage the files just yet so I added them with
git add
and then just didgit reset
. This basically just added and then unstaged my changes but cleared the unmerged paths.If, like me, what you usually want is to overwrite the contents of the working directory with that of the stashed files, and you still get a conflict, then what you want is to resolve the conflict using
git checkout --theirs -- .
from the root.After that, you can
git reset
to bring all the changes from the index to the working directory, since apparently in case of conflict the changes to non-conflicted files stay in the index.You may also want to run
git stash drop [<stash name>]
afterwards, to get rid of the stash, becausegit stash pop
doesn't delete it in case of conflicts.Note that
Git 2.5 (Q2 2015)a future Git might try to make that scenario impossible.See commit ed178ef by Jeff King (
peff
), 22 Apr 2015.(Merged by Junio C Hamano --
gitster
-- in commit 05c3967, 19 May 2015)Note: This has been reverted. See below.
Problem
In other words:
Solution
See commit 1937610 (15 Jun 2015), and commit ed178ef (22 Apr 2015) by Jeff King (
peff
).(Merged by Junio C Hamano --
gitster
-- in commit bfb539b, 24 Jun 2015)