9

When I try to pull I have the following message:

Automatic merge failed; fix conflicts and then commit the result.

So, I try to fix conflict (as git suggest) for that I follow these instructions.

Among the first things that I need to do is to open the "problematic" file in a text editor and find lines like that

If you have questions, please
<<<<<<< HEAD
open an issue
=======
ask your question in IRC.
>>>>>>> branch-a

The problem is that I do not see things like that in my file. In particular I searched for HEAD and it is not there.

3
  • 1
    Does git status list any files which "both" sides modified? Are you certain that you are looking at the right file, and that you searched the whole file for the conflict markers? Commented Dec 1, 2017 at 7:52
  • 1
    In some editors, you need to reopen the file to see the conflict markers, those editors don't watch for file changes in the background (some are even worse and overwrite the file again with their own changes)
    – Ferrybig
    Commented Dec 1, 2017 at 8:06
  • Popular post listing many options (e.g. Meld, DiffMerge, KDiff3) is here: stackoverflow.com/questions/137102/…
    – TT--
    Commented Nov 11, 2018 at 15:03

1 Answer 1

18

There are several ways to solve git conflicts, I will explain here using GUI and text editor way.

Solving git conflict using text editor.

Open any one of your favourite editor, example, Notepad, gedit, vim, nano or even Eclipse.

  1. Whenever there is conflict in a file git add conflict marker that looks like this <<<<<<<<.

  2. When you open the file in your text editor, you'll see the changes from the HEAD or base branch after the line <<<<<<< HEAD

  3. ========, it divides your changes from the other branch as >>>>>>>>YOUR_BRANCH_NAME

  4. You can decide if you want keep your branch changes or not. If you want to keep the changes what you did, delete the conflict marker they are,<<<<<<<, =======, >>>>>>> and then do a merge.

Commands to commit the changes.

git add . or git add "your_file"
git commit -m "Merge conflicts resolved"

Solving git conflict your GUI

What if you have so many merge conflicts in files? In that case you can use GUI, well its just personal choice whether to opt for GUI or not. In GUI, you can see side by side diff. It is easy for the beginners to see the changes.

You need to configure your git to use the mergetool you want to use. Example: meld, kdiff3 or vimdiff. Again it's upto the user what they prefer. I use meld. Here you need to install these tool, after installation you have to configure it.

git config merge.tool meld 

you can solve merge conflicts

git mergetool -t meld

Then you can follow the step 2 to 4 from solving using text editor, to solve the merge conflicts.

2
  • I see some string, probably an id, instead of "YOUR_BRANCH_NAME". What is that id for ?
    – MasterJoe
    Commented Aug 15, 2018 at 0:27
  • See: Setting up and using Meld as your git difftool and mergetool: stackoverflow.com/q/34119866/2102457
    – mattst
    Commented Aug 29, 2019 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.