How to resolve conflict in eclipse egit

12,510

I am posting this answer to describe how to manually resolve merge conflicts in Git. This is the usual method I use, because I prefer to not have an interface sitting on top of Git when I do things. Consider one conflict in your file:

<<<<<<< HEAD
    Thread.sleep(1500);
=======
    Thread.sleep(1400);
>>>>>>>

The <<<<<<, >>>>>>>, and ======= symbols are conflict markers, and they tell you the area in the file where there is a conflict. A conflict can be thought of two different versions of the same story. In the above case, one parent in the merge wants to sleep for 1500ms, while the other wants to sleep for 1400ms. You need to decide which version is the one you want after the merge. Assuming the former, you would delete all the above 5 lines except for the line containing the actual call to Thread.sleep() which you want to retain. Hence, you would be left with this:

    Thread.sleep(1500);

Repeat this process for all conflicts. Once you are done, do a file-scoped search for ======= and the other markers. If you don't find them, and you are confident in your merging logic, then you are done. You should be able to right click the file in Eclipse and do "Add to index." This marks the file as having been resolved.

Note that you could also consider using Eclipse's merge tool. In this case, you would be presented with two different versions of the file, and you could choose from either or both versions to resolve the conflict.

Share:
12,510
NarendraR
Author by

NarendraR

I'm an Automation Engineer working with Selenium using Java. I'm always passionate about new Learning and problem solving. Always seeks time to be a helpful hand over here Get in touch with me on LinkedIn

Updated on June 04, 2022

Comments

  • NarendraR
    NarendraR almost 2 years

    I'm newbie in Github integration with eclipse. After committing my changes I have taken pull and it showing conflict in one file.

    Find below details :

    enter image description here

    I want to neglect my changes and keep the other user changes. I am stuck at how to do this. Tried merging in following way :

    enter image description here

    It is showing comparison in that file but I am not able seeing the option to revert my changes and keep the other users changes

    This is comparison file :

    enter image description here

    Can anyone help me to do this