Many people prefer command line over GUI because it is more efficient for most of the day-to-day tasks of a programmer. In short, “Command line is Love”. But in the case of resolving the conflicts “GUI is Magic”.
In this post, I will be covering How to resolve merge conflicts through GUI. You will find a very similar experience in any other famous IDE that you use.
Let’s take an example where you have testBranch and you wanted to merge updated master into your testBranch. And for doing so run:
git merge master
And consider that you have some conflicts with master branch. In the version control tab you will see something like this:
Click on Resolve text. It will open a prompt showing all the files having conflicts. If you are sure that for the selected file, you just want to take the changes from the single source then you can just click on “Accept Yours/Accept Theirs” accordingly.
If you want to take the changes from both the branch click on “Merge..” and it will open the merging window like below:
Now a little about merging window as per Goland Documentations: “GoLand provides a tool for resolving conflicts locally. This tool consists of three panes. The left pane shows the read-only local copy; the right pane shows the read-only version checked in to the repository. The central pane shows a fully-functional editor where the results of merging and resolving conflicts are displayed. Initially, the contents of this pane are the same as the base revision of the file, that is, the revision from which both conflicting versions are derived”.
You can make use of little >>, <<, and x buttons in selecting which changes you want to take in the merge. For example, I have clicked << button on line 58, 83, and >> button on line 85. Just like that, In just three clicks I have merged this file(The new version is shown in the middle). Now, Click on apply.
If you are thinking that: Okay, this is good but not something someone says Magic.
Hold that thought.
Let’s merge the second file now: You must have seen the conflicts like this if you were doing it manually. What you get from just seeing the below code?: What the hell happened here, right?
Now, try merge option on this file(See below image). It becomes crystal clear what you are dealing with. In one change, you have moved initialization out of the loop and In second change, you have moved the increments inside the loop.
In the above image, it was very hard to understand what happened and what you want to take but through this approach, you know exactly what happened and you can make an informed choice at the time of merging. This kind of clarity makes this process Magic.
With just a few clicks, you will be able to get both features in the result panel.
Using GUI in resolving conflicts reduces the chances of mistakes(Things are more clear) and it is much faster than the traditional approach.