First step, install KDiff3.
It's not the prettiest GUI in the world, but once you get used to it it is quite usable and has the added advantage of working quite naturally with Git without having to configure much.
Second step, open your .gitconfig
(in your home directory, C:\Users\(username)
, or down ye olde Documents and Settings
path), and add the following:
[diff]
tool = kdiff3
[merge]
tool = kdiff3
[mergetool "kdiff3"]
path = C:/Program Files/KDiff3/kdiff3.exe
keepBackup = false
trustExitCode = false
Now all calls to git difftool
and git mergetool
should default to KDiff3.
That's all you need to be good to go!
Much simpler than bothering with all those wrappers.
You will find a good tutorial here (in the excellent gitguru):
git mergetool
The git mergetool
command allows for the integration of those tools into the merge process. Run after merge conflicts have been identified, it loops through the files that need to be resolved and provides the specified tool with the version information necessary to invoke the 3-way merge.
git mergetool
already includes support for a number open source and freely available merge tools: kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff.
Support for additional tools including DiffMerge and Araxis Merge can be added via custom configuration settings provided a command-line call exists:
git config --global mergetool.[tool].cmd [command-line call]
git config --global mergetool.[tool].trustExitCode [true|false]
The “--global
” flag is used so the setting will apply across all of your Git repositories.
The command line needs to accept the following file variables passed in as parameters:
$LOCAL
– Current branch version
$REMOTE
– Version to be merged
$BASE
– Common ancestor
$MERGED
– File where results will be written
git mergetool
will create the versions as temporary files and set the variables appropriately before the tool command-line is executed.
If the tool returns a proper exit code after a successful or unsuccessful merge, then the trustExitCode
setting can be set to true. Otherwise set it as false so you will be prompted as to whether the merge conflicts for a file were resolved.
Performing a Merge with Conflicts
The sequence of commands for a merge using mergetool would be
git merge
git mergetool -t [tool]
git add .
git commit
You can specify a default tool via the merge.tool setting
git config --global merge.tool [tool]
This will allow you to just simply call
git mergetool