1

I have a few tens of files that Git has added merge-conflict markers to, yet Git does not acknowledge that there is a merge conflict and will not open the mergetool:

 1 <<<<<<< HEAD                                             
 2 <?php
 3 require_once('../auth_header.php');
 4 require_once($_SERVER['DOCUMENT_ROOT'].'/init.php');
 5 
 6 =======
 7 <?
 8 require '../auth_header.php';
 9 
10 >>>>>>> development


$ git mergetool
No files need merging

I'm now editing those files by hand. Is there any way to use a proper merge-conflict tool with a file that is formatted as above? I don't necessarily need comparison with the BASE file, just a way to diff and select the two 'sides' of files as that shown above without manually erasing sections and markers. I would of course prefer to stay in VIM.

All merge-conflict tools that I've tried, such as kdiff3 need two files to diff. They do not seem to support merge-conflict markers.

dotancohen
  • 30,064
  • 36
  • 138
  • 197
  • You want to read this: http://vim.wikia.com/wiki/A_better_Vimdiff_Git_mergetool – Kent Jan 05 '15 at 11:29
  • I actually do have the `diffconflicts` script set up, but git still returns `No files need merging`. I need a way to open **a single file** with conflict markers. – dotancohen Jan 05 '15 at 11:42
  • In particular the [Conflict2Diff plugin](http://www.vim.org/scripts/script.php?script_id=621) mentioned at the end of the Wiki page. – Ingo Karkat Jan 05 '15 at 11:46
  • Thank you Ingo. Please post that plugin as an answer as it exactly solves the issue. Thank you! – dotancohen Jan 05 '15 at 12:37
  • @dotancohen Are you sure you still have a conflict and these files are not the backups (file names ending in `.orig`)? – musiKk Jan 05 '15 at 13:59
  • @musiKk: Yes, I'm sure. I'm not sure how this happened, and it is in fact the second time that it has happened with this project. In both cases we merged in branches that were merged off of master many months ago and there were too many changes to both master and to the feature branch. Today we are implementing a policy of merging in from master every start and end of the work day. – dotancohen Jan 05 '15 at 14:13
  • @dotancohen Ok, I just wanted to make sure. I don't recall ever experiencing this particular problem—even in big merges. – musiKk Jan 05 '15 at 14:26
  • Are you sure that the conflict did not occur in an earlier commit? Git should not let a merge go through if there are merge conflicts. Try `git log -S'<<<<<<' --all` to see if whcih commit introduced the offending characters. – Joseph K. Strauss Jan 05 '15 at 14:30
  • @JosephK.Strauss: Thank you, it seems that you are right. These conflict markers have been lurking in the code for over a week, in a feature branch which has not been tested. I'll speak to the dev who committed them. Thank you! – dotancohen Jan 05 '15 at 15:16

2 Answers2

2

Git will not insert these characters without telling you that there was a conflict. It will not even automatically commit even when using --rerere-autoupdate flag, and there are no other conflicts. This is to make sure that you know that there was a conflict, and that you resolve it appropriately.

Of course, this does not mean that you cannot "outsmart" Git, and add the files anyway with the conflicts still in place. If you suspect that this is the issue, try finding who did this with

git log -S'<<<<<<' --all  
Community
  • 1
  • 1
Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40
  • Thank you, you have found the culprit as to **why** these conflict markers are in the code. However, I need to accept Ingo's suggestion of the VIM plugin to use to resolve the issue, as that was the question asked. But thank you for helping to find the root cause! – dotancohen Jan 05 '15 at 15:41
1

The ConflictToDiff plugin can split a (it says CVS, but also works for other tools) conflict file (i.e. containing <<<<<<<< markers) back into the conflicting versions, and offers commands to merge them.

Alternatively, my ConflictMotions plugin defines movement commands and text objects to go to and operate on conflicting lines. With it, you can resolve the conflicts in the original file.

If those conflict markers have been committed, use the blame functionality to find the originator and speak to him.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324