Using SourceGear DiffMerge with TFS in Visual Studio and Git
This article shows you how to configure TFS and Git to use SourceGear DiffMerge.
This post isn't to advocate DiffMerge over another file comparer, but an explanation on how to set up DiffMerge with either TFS in Visual Studio or Git.
I've been using DiffMerge since VS2010, so pretty much forever as far as I am concerned. Back then there was no built in diff viewer in Visual Studio so you had to use a third party tool. Because I’ve used it for so long I'm quite reluctant to change. Looking at differences in files is something every developer does often, whether it is local code changes or a code review for another member of the team. It has to be a quick and efficient process. That’s why I stick with DiffMerge. I know it works, I know how to use it, I'm familiar with the layout and I can quickly navigate and scan the document.
These are the settings I use and an explanation on the flags and arguments.
Configuring DiffMerge with TFS in Visual Studio
From the Visual Studio toolbar select: Tools -> Options -> Source Control
Make sure Current source control plug-in: has Visual Studio Team Foundation Server selected.
Then select Visual Studio Team Foundation Server -> Configure User Tools... and add settings for compare and merge.
Compare settings
Extension: .*
Command: C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe
Arguments: /title1=%6 /title2=%7 %1 %2
Merge settings
Extension: .*
Command: C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe
Arguments: /m /title1=%6 /title2=%7 /title3=%8 /c=%9 %1 %3 %2 /r=%4
Compare argument parameters
The compare argument parameters and their meaning:
- %1 = Original file, the pre-changes file
- %2 = Modified file (in diff, the post-changes file
- %6 = Original file label (The label for the %1 file)
- %7 = Modified file label (The label for the %2 file)
Merge flags and argument parameters
The merge flags and their meaning:
- /m = Runs Auto-Merge immediately after loading the files.
- /title1 = Sets the File Panel Label for the first file/column.
- /title2 = Sets the File Panel Label for the second file/column.
- /title3 = Sets the File Panel Label for the third file/column.
- /c = A caption for the application title bar of the first window
- /r = Specifies a pathname for saving the merge result. If no pathname is specified then if saved the center file will be overwritten.
The merge argument parameters and their meaning:
- %1 = Original file, the "server" or "theirs" file, the file that is the base file after "their" changes were applied
- %2 = Modified file, the "yours" file - the base file with "your" changes applied
- %3 = Base file (in the 3-way merge operation, the file which both “theirs” and “yours” are derived from – the common ancestor. This doesn’t mean it’s the version the changes were based from, since this may be a cherry-pick merge)
- %4 = Merged file (The output file for the merge operation - the filename that the merge tool should write to)
- %6 = Original file label (The label for the %1 file)
- %7 = Modified file label (The label for the %2 file)
- %8 = Base file label (The label for the %3 file)
- %9 = Merged file label (The label for the %4 file)
Reference links and recommended reading.
diff/merge configuration in Team Foundation – common Command and Argument values
Integration with Microsoft TFS
Using DiffMerge with Git
Diffmerge can also be used with Git version control. The following lines must be added to .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
Compare
The compare argument parameters:
- $LOCAL = The original file
- $REMOTE = The modified file
Using the order above, the original file will appear on the left and the modified on the right.
Merge
The merge flags:
- merge = auto merge
- result = save file
The merge argument parameters:
- $MERGED = merged file
- $LOCAL = the original file
- $BASE = the Base file
- $REMOTE = the modified file
Reference links and recommended reading.
Integration with GitHub for Windows or Git Bash Shell
File icon made by Prosymbols from www.flaticon.com is licensed by CC 3.0 BY