How to Set Up SourceGear DiffMerge Tool for Git
This article will discuss configuring Git to use SourceGear’s DiffMerge
as the default difftool
. This tool allows us to easily understand merge conflicts with improved visuals compared to Git’s default difftool
.
It is the ideal tool for a 3-way merge since it supports 3-way file comparison.
We can view the previous state of a file, the current state, and the result after a merge. You must download and install DiffMerge
from SourceGear’s official website.
Set Up DiffMerge
on Windows
To set up Git to use the DiffMerge
tool by default, add this to your .gitconfig
file.
[diff]
tool = DiffMerge
[difftool "DiffMerge"]
cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' "$LOCAL" "$REMOTE"
[merge]
tool = DiffMerge
[mergetool "DiffMerge"]
cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' -merge -result="$PWD/$MERGED" "$PWD/$LOCAL" "$PWD/$BASE" "$PWD/$REMOTE"
trustExitCode = true
[mergetool]
keepBackup = false
For the compare argument parameters, we have:
$LOCAL
, which is the original file.$REMOTE
, which is the modified file.
You can run the git difftool
and git mergetool
commands on Git Bash to open the DiffMerge
.
Alternatively, you can run the commands below on your command prompt to update the .gitconfig
file.
C:\> git config --global diff.tool diffmerge
C:\> git config --global difftool.diffmerge.cmd
"C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe
\"$LOCAL\" \"$REMOTE\""
C:\> git config --global merge.tool diffmerge
C:\> git config --global mergetool.diffmerge.trustExitCode true
C:\> git config --global mergetool.diffmerge.cmd
"C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe
-merge -result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\""
Set Up DiffMerge
on Mac OS
The process of configuring Git to use DiffMerge
on Mac OS is perhaps the most straightforward. Make sure you have the directory below.
/usr/local/bin/diffmerge
Run the commands below to update your .gitconfig
file and test it out.
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd "/usr/local/bin/diffmerge --merge --result=\"\$MERGED\" \"\$LOCAL\" \"\$BASE\" \"\$REMOTE\""
git config --global mergetool.diffmerge.trustExitCode true
git config --global mergetool.keepBackup false
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/usr/local/bin/diffmerge --nosplash \"\$LOCAL\" \"\$REMOTE\""
We can run the git config --global -e
command to inspect our .gitconfig
file. It should look something like this:
[diff]
tool = diffmerge
[merge]
tool = diffmerge
...
[mergetool "diffmerge"]
cmd = /usr/local/bin/diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
trustExitCode = true
[mergetool]
keepBackup = false
[difftool "diffmerge"]
cmd = /usr/local/bin/diffmerge --nosplash \"$LOCAL\" \"$REMOTE\"
Set Up DiffMerge
on Ubuntu
Configuring on Ubuntu is very much similar to Mac OS. We will use the same commands but change the installation location.
Here are the commands.
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd "/usr/bin/diffmerge --merge --result=\"\$MERGED\" \"\$LOCAL\" \"\$BASE\" \"\$REMOTE\""
git config --global mergetool.diffmerge.trustExitCode true
git config --global mergetool.keepBackup false
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/usr/bin/diffmerge --nosplash \"\$LOCAL\" \"\$REMOTE\""
That’s pretty much it. We can now run the commands below to test it out.
$ git mergetool
$ git difftool
To sum up, if you want to configure Git to use SourceGear’s DiffMerge
tool, you will need to update your .gitconfig
file with the listed commands based on your operating system.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn