Merge conflict resolution

Chris Calo picture Chris Calo · Feb 9, 2012 · Viewed 27.5k times · Source

When there's a merge conflict in Git, junk like the following is inserted into the conflicting files. Three questions:

  1. How do you read these annotations?
  2. What are some strategies to use when fixing these merge conflicts?
  3. Is there a GUI tool for Mac that knows how to read these files and display the two versions side-by-side to make it easier to fix the problem?

enter image description here

Note: In case it's relevant, I am using GitHub's Mac GUI client.

Answer

Simon Richter picture Simon Richter · Feb 9, 2012

Everything between <<<<<< and ====== comes from the HEAD revision, which is the committed state before starting the merge operation (git merge will complain if the tree is dirty, so it should be equivalent to your working directory).

The parts between ====== and >>>>>> come from the version being merged. The text after the >>>>>> is the comment of the commit that introduced the conflicting change.

That there is a conflict marker means that the base version of this part of the file is different from both "new" versions. The base version (last common ancestor) is not shown.

If you want a more comfortable merge and have a GUI available, I suggest you take a look at kdiff3.