07975 997026 enquiries@ harpanet.com
After installing GitHub for Windows, the default Merge Tool is configured as Beyond Compare (a commercial file comparison package). WinMerge is also an excellent tool for comparing file differences under Windows, and has the benefit of being free.
Configuring Git to use WinMerge is very straightforward…
* First, download WinMerge (http://winmerge.org/) and install it as normal.
* I am assuming you already have GitHub for Windows installed and configured, but if not you can find it here: https://windows.github.com - come back to these instructions when you are more familiar with GitWin.
I am using the portable version of WinMerge, which I have stored in
e:\apps\WinMergePortable\WinMergePortable.exe and these instructions use that. For a conventional install of WinMerge, just change the path to the file. Tip: make a note of the full drive and file path as you will need to enter it below.
* Open up GitWin and open any repository you have created * Click the 'cog' icon in the top right corner
It doesn't matter which repository you choose to run the shell for, as we are setting global settings below that apply to all repositories.
Git uses two tools which can be slightly confusing for some.
difftool is like using a 'Read Only' version of WinMerge. It doesn't let you change anything, it just shows you the difference between two files.
mergetool is the tool that lets you fix any file conflicts when merging between branches in Git. In most cases it is the 'mergetool' that people want to configure to gain a visual way of fixing merge conflicts, so we will do that first.
In the Shell window, we need to run the following two commands individually:
git config --global merge.tool winmerge git config --global --replace mergetool.winmerge.cmd "e:/apps/WinMergePortable/WinMergePortable.exe -e -ul -ur -dl \"Base: $MERGED\" -dr \"Mine: $REMOTE\" $MERGED $REMOTE"
In the first command, we are setting a Git variable named
merge.tool to the value
winmerge. This tells Git to run
winmerge when the
merge.tool is called.
In the second line we are defining the command that should be executed when the
merge.tool is called. Note the following in this line above:
* We use forward slashes
/ in the path, NOT back slashes, because back slashes are treated as 'escape' symbols;
\” entries around the text strings are creating 'escaped' apostrophes so that they are not confused with the apostrophes around the entire command;
* We are using the Git
$REMOTE variables to indicate the files to be compared/merged.
$MERGEDvariable contains the file created by Git when it found a conflict during the merge attempt;
$REMOTEvariable contains the file that you are attempting to merge into the current repository
Now, when you get a response similar to the following…
Automatic merge failed; fix conflicts and then commit the result.
… you can run
git mergetool to try and resolve the conflicts visually.
In a very similar manner to above, we can use WinMerge to show us the difference between two files. In the Shell window, this time run the following two commands individually:
git config --global diff.tool winmerge git config --global difftool.winmerge.cmd "e:/apps/WinMergePortable/WinMergePortable.exe -e -ul -ur -wl -wr -dl \"Local: $LOCAL\" -dr \"Remote: $REMOTE\" $LOCAL $REMOTE"
You will notice a few slight differences:
* We are defining the
diff.tool variables this time;
* We have added
-wr to the command line, which are WinMerge's options to make the left and right files 'Read-Only';
* We are using the
$REMOTE file variables this time (there is no
$MERGED variable as we are not merging across branches);
Now you can run the following command to compare two files:
git difftool <branch1> <branch2> -- <filename to compare>