Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving Git conflicts in SourceTree

I was using NetBeans GIT plugin before, then I've decided to switch to SourceTree, as it is more efficient and powerful. As a newcomer to SourceTree I've managed to figure out basic Pull, Push and Commit workflows.

However, I got stuck when there were file conflicts when merging with my friend's work. In NetBeans if there are any conflicts, the plugin suggest to resolve it in a popup and I just want to go to the conflict resolving interface and accept the correct code chunk by clicking a button. That was simple.

In SourceTree, there is something called External Merge Tool which didn't work well for me. When I right click on the file with conflicts, it just opened up two files side by side and there were arrows pointing left to right in the middle. There is a dropdown at the bottom of the screen to select the arrow direction.

I tried to use this interface to resolve conflicts, but I failed. It didn't fix the conflicts and merged two files.

As I searched through the internet I found that some people use external SourceTree conflict solving plugins to merge. Actually I'm little lost here. That's why I've decided to post this problem here as this might help someone like me one day.

I know there are lots of people who have been using SourceTree for a long time. Could any of them please tell me, how to resolve conflicts in SourceTree effectively?

Should I use an external plugin or should I use the External Merge Tool (if so, how can I use this)?

like image 374
stackflow Avatar asked Jun 11 '14 07:06

stackflow


People also ask

How do I merge files in Sourcetree?

Under Branches, double-click the feature branch that is behind to switch to that branch. Click the Merge button. From the popup that appears, select the commit you want to merge into your feature branch. Check the Create a commit even if merge resolved via fast-forward option at the bottom.

What is a Git conflict and how are they resolved?

Luckily, Git offers powerful tools to help navigate and resolve conflicts. Git can handle most merges on its own with automatic merging features. A conflict arises when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other.


1 Answers

I'm using SourceTree along with TortoiseMerge/Diff, which is very easy and convinient diff/merge tool.

If you'd like to use it as well, then:

  1. Get standalone version of TortoiseMerge/Diff (quite old, since it doesn't ship standalone since version 1.6.7 of TortosieSVN, that is since July 2011). Links and details in this answer.

  2. Unzip TortoiseIDiff.exe and TortoiseMerge.exe to any folder (c:\Program Files (x86)\Atlassian\SourceTree\extras\ in my case).

  3. In SourceTree open Tools > Options > Diff > External Diff / Merge. Select TortoiseMerge in both dropdown lists.

  4. Hit OK and point SourceTree to your location of TortoiseIDiff.exe and TortoiseMerge.exe.

After that, you can select Resolve Conflicts > Launch External Merge Tool from context menu on each conflicted file in your local repository. This will open up TortoiseMerge, where you can easily deal with all the conflicts, you have. Once finished, simply close TortoiseMerge (you don't even need to save changes, this will probably be done automatically) and after few seconds SourceTree should handle that gracefully.

The only problem is, that it automatically creates backup copy, even though proper option is unchecked.

There is an alternate solution to this problem, which uses KDiff3 instead of TortoiseDiff / TortoiseMerge.

like image 112
trejder Avatar answered Sep 25 '22 09:09

trejder