14

Pretty new to git and have a bit of an issue i'm not sure how to fix. I mistakenly made a change to one file in a working copy and didn't commit the change. I then made changes to another copy and committed them - when I tried to pull the changes I unsurprisingly got an error saying my "local changes to the file would be overwritten by merge, aborting". So I removed the offending file using git rm, then used git add -u and committed the deletion. I then tried to pull in the latest copy and got the following. What's the best way to deal with this? grateful for any pointers

CONFLICT (delete/modify): wp-content/plugins/wp-flash-countdown/xml_option_.xml deleted in HEAD and modified in ba878ab1efe3a039961a446c490d5c93a2bc22e1. Version ba878ab1efe3a039961a446c490d5c93a2bc22e1 of wp-content/plugins/wp-flash-countdown/xml_option_.xml left in tree.
Automatic merge failed; fix conflicts and then commit the result.
bsod99
  • 1,287
  • 6
  • 16
  • 32
  • Possible duplicate of [git - merge conflict when local is deleted but file exists in remote](https://stackoverflow.com/questions/4319486/git-merge-conflict-when-local-is-deleted-but-file-exists-in-remote) – IMSoP Jul 19 '19 at 09:30

3 Answers3

15

If you now do git status, its output contains:

# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)

If you git rm them, a needs merge warning will be output but nevertheless the removal will succeed, then you can commit the modifications - this will be the "merge commit".

thSoft
  • 21,755
  • 5
  • 88
  • 103
7

SO at this point do you have the file in the working copy that you pulled to?

if so just delete it and recommit.

j_mcnally
  • 6,928
  • 2
  • 31
  • 46
  • I just tried that, recommitted and then pulled again - this time geting `Pull is not possible because you have unmerged files. Please, fix them up in the work tree, and then use 'git add/rm '` - it also listed as adding files which i'd just removed from that working copy as they weren't being tracked – bsod99 Oct 09 '12 at 23:33
  • ok, so it is just that one file that's causing the problem - tried to delete with git rm but get a "needs merge" error – bsod99 Oct 10 '12 at 00:00
  • in the end, got it sorted, with effectively your solution and a few needless extra steps from me! – bsod99 Oct 10 '12 at 00:09
2

Had a similar problem with a cheesy WordPress host. Try this..

git log --follow -- readme.html

Note the commit id of the last time that file existed (like before you deleted it.) Now you want to "checkout" that file from git.

git checkout (commit id) readme.html

Then add, commit, push, etc. Worked for me!

PJ Brunet
  • 3,615
  • 40
  • 37