How to configure Git on Windows (under Cygwin) to use Beyond Compare 3

Let’s get to the point.
To configure Git on Windows (under Cygwin) to use Beyond Compare 3, you should have the following in your .gitconfig file (e.g. C:\cygwin\home\<user>\.gitconfig):

[diff]
    tool = mybc3
[difftool "mybc3"]
    cmd = \"c:/program files/beyond compare 3/BComp.com\" \"$(cygpath -w \"$LOCAL\")\" \"$(cygpath -w \"$REMOTE\")\" /lefttitle=\"$(cygpath -w \"$LOCAL\")\" /righttitle=\"$(cygpath -w \"$REMOTE\")\" /leftreadonly /rightreadonly
[difftool]
    prompt = false
[merge]
    tool = mybc3
[mergetool "mybc3"]
    cmd = \"c:/program files/beyond compare 3/BComp.com\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\" /lefttitle=\"$LOCAL\" /righttitle=\"$REMOTE\" /centertitle=\"$BASE\" /outputtitle=\"$MERGED\" /leftreadonly /rightreadonly /centerreadonly
    keepBackup = false
    trustExitCode = true
[mergetool]
    prompt = false


A bit of explanation for the curious:

The Beyond Compare 3 Help > Command Line Reference states the following:

Command Line Parameters

BCompare.exe C:\File1.ext C:\File2.ext
Opens the specified files in the associated file view.

BCompare.exe C:\Left.ext C:\Right.ext C:\Center.ext C:\Output.ext
Opens a Text Merge view with the specified files in the left, right, center, and output panes.

Command Line Executable Files

BCompare.exe
This is the main application. Only one copy will run at a time, regardless of how many windows you have open. If you launch a second copy it will tell the existing copy to start a comparison and exit immediately.

BComp.exe
This is a Win32 GUI program. If launched from a version control system, it should work just fine. If launched from a console window, the console (or batch file) will not wait for it.

BComp.com (<- this is the one I use)
This is a Win32 console program. It has to have a console; if you launch it from one (or a batch file) that console will wait for the comparison to complete before returning. If you launch it from a version control system interactively, it will show a console window while it’s waiting.

The knowledge base at Scooter Software has some minimal and somewhat incomplete documentation about the integration too.

The git-difftool documentation explains the following:

$LOCAL is set to the name of the temporary file containing the contents of the diff pre-image and
$REMOTE is set to the name of the temporary file containing the contents of the diff post-image.

The git-mergetool documentation explains the following:

$BASE is set to the name of a temporary file containing the common base for the merge, if available;
$LOCAL is set to the name of a temporary file containing the contents of the file on the current branch;
$REMOTE is set to the name of a temporary file containing the contents of the file to be merged, and
$MERGED is set to the name of the file to which the merge tool should write the result of the merge resolution.

The $(cygpath -w \"$LOCAL\") part converts $LOCAL to a Windows format path. The quotation marks (\") are necessary for file names with spaces.
Concerning Beyond Compare 3 as a merge tool, it is not necessary to use the $(cygpath -w ...) syntax.

I update my .gitconfig file in my user’s home directory in Cygwin because I want the configuration to be global. If you want a per repository configuration, change the .git/config file in your Git repository instead.

I call the tool “mybc3” instead of “bc3” because it seems that the value “bc3” has a fixed cmd line and cannot be changed with a corresponding mergetool.bc3.cmd option.

Putting everything together, you get (without character escaping):

[difftool "mybc3"]
    cmd = "c:/program files/beyond compare 3/BComp.com"
                 "$(cygpath -w "$LOCAL")"
                 "$(cygpath -w "$REMOTE")"
                 /lefttitle="$(cygpath -w "$LOCAL")"
                 /righttitle="$(cygpath -w "$REMOTE")"
                 /leftreadonly
                 /rightreadonly

[mergetool "mybc3"]
    cmd = "c:/program files/beyond compare 3/BComp.com"
                 "$LOCAL"
                 "$REMOTE"
                 "$BASE"
                 "$MERGED"
                 /lefttitle="$LOCAL"
                 /righttitle="$REMOTE"
                 /centertitle="$BASE"
                 /outputtitle="$MERGED"
                 /leftreadonly
                 /rightreadonly
                 /centerreadonly

1 Comments.

  1. Thank you for the tip!
    Keep them coming.