Configure External Diff Tool

When you have to solve conflicts in git. You normally would see the conflict marked in the same file but in a cumbersome to edit it by hand.

So it is better to have a graphical user interface that helps in identifying the changes and do it graphically. The purpose of this document is to setup such a tool to use inside the git command tool in the terminal.

As a reference of merge conflicts situations, take a look into Understanding merge conflicts.

Installing Visual Merge Tool

Go to the following link to download Helix Visual Merge Tool.

You will see a link like the following.

Perforce Visual Merge Tool Home Page
Figure 1. Perforce Visual Merge Tool Home Page

Once you have it downloaded, execute the installer program following your Operating System conventions, for the sake of this guide, it will use the 'Microsoft Windows' Operating System.

Visual Merge Tool Setup
Figure 2. Visual Merge Tool Setup

Click 'Next' button.

Visual Merge Tool Setup (Client Config)
Figure 3. Visual Merge Tool Setup (Client Config)

Select fields as shown in the last picture and then click 'Next' button.

Visual Merge Tool Setup Start
Figure 4. Visual Merge Tool Setup Start

Click 'Install' button.

Visual Merge Tool Installing
Figure 5. Visual Merge Tool Installing

At this point it will make the setup process, it will take some minutes to complete, after that you will see the following.

Visual Merge Tool Installation Complete
Figure 6. Visual Merge Tool Installation Complete

Notice that the installation needs to restart your computer for the configurations to take effect.

Click Restart now to complete the setup process, after you restart you will see the following.

Visual Merge Tool Installation Restart Complete
Figure 7. Visual Merge Tool Installation Restart Complete

Configuring Git Merge Tool

In this section we will indicate the steps to make the 'git client' to use the external tool in order to resolve merge conflicts in a confortable way.

First step is to indicate git tool which will be the external diff merge tool. Open a git bash terminal and type the following.

$ git config --global merge.tool p4merge

This will add an entry key in the global git bash configuration settings file.

Now it is time to indicate git bash what is the external path to use to associate to the merge.tool.

$ git config mergetool.p4merge.path "C:\Program Files\Perforce\p4merge.exe"

Notice the path is expressed in the Operating System specific syntax.

Now that we have the merge tool git bash will use to resolve conflicts in a more visual way, it is time to see it in action.

$ git mergetool

To have a visual cue of the Visual Merge Tool in action, I followed the tutorial steps in Understanding merge conflicts.

Now if you execute the command git mergetool, git will execute the external configured merge tool, by showing the following screenshot.

If you need more information about how to use the 'Visual Merge Tool' you can open the help menu in the program which leads to the following link P4Merge Help. Notice that it is best to open the link from within the program as it may change the version.

Visual Merge Tool (Resolve git Conflict)
Figure 8. Visual Merge Tool (Resolve git Conflict)

As per the tutorial, the conflict is in the file 'merge.txt' file, to which git creates the following files underneath to pass them to the 'Visual Merge Tool' in order to accomplish its task.

  • merge_BACKUP_707.txt

  • merge_REMOTE_707.txt

  • merge_LOCAL_707.txt

  • merge_BASE_707.txt

After you have resolved the conflict, you must save the changes in the tool.

After you have resolved the conflicts and saved the changes it will tell git that the conflict was resolved. But a copy of the original conflict was created by the 'Visual Merge Tool' which needs to be removed before commiting the mergeed versions.

If you have more than one file in conflict, it will open the 'Visual Merge Tool' for each of the conflict files and you repeat the steps described to solve the conflicts, after all of the conflicts are resolved you simply add a commit to finish the merge process to indicate the conflicts were resolved.