114

I have succeeded in getting git to start Beyond Compare 3 as a diff tool however, when I do a diff, the file I am comparing against is not being loaded. Only the latest version of the file is loaded and nothing else, so there is nothing in the right pane of Beyond Compare.

I am running git 1.6.3.1 with Cygwin with Beyond Compare 3. I have set up beyond compare as they suggest in the support part of their website with a script like such:

#!/bin/sh  
# diff is called by git with 7 parameters:  
# path old-file old-hex old-mode new-file new-hex new-mode  
"path_to_bc3_executable" "$2" "$5" | cat

Has anyone else encountered this problem and know a solution to this?

Edit:
I have followed the suggestions by VonC but I am still having exactly the same problem as before. I am kinda new to Git so perhaps I am not using the diff correctly.

For example, I am trying to see the diff on a file with a command like such:
git diff main.css

Beyond Compare will then open and only display my current main.css in the left pane, there is nothing in the right pane. I would like the see my current main.css in the left pane compared to the HEAD, basically what I have last committed.

My git-diff-wrapper.sh looks like this:

#!/bin/sh  
# diff is called by git with 7 parameters:  
# path old-file old-hex old-mode new-file new-hex new-mode  
"c:/Program Files/Beyond Compare 3/BCompare.exe" "$2" "$5" | cat

My git config looks like this for Diff:

[diff]  
external = c:/cygwin/bin/git-diff-wrapper.sh
Manfredo
  • 1,330
  • 2
  • 17
  • 46
Avanst
  • 1,835
  • 5
  • 18
  • 19

19 Answers19

144

I don't use extra wrapper .sh files. My environment is Windows XP, git 1.7.1 on cygwin, and Beyond Compare 3. Following is my .git/config file.

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    #use cygpath to transform cygwin path $LOCAL (something like /tmp/U5VvP1_abc) to windows path, because bc3 is a windows software
    cmd = \"c:/program files/beyond compare 3/bcomp.exe\" "$(cygpath -w $LOCAL)" "$REMOTE"
[merge]
    tool = bc3
[mergetool]
    prompt = false
[mergetool "bc3"]
    #trustExitCode = true
    cmd = \"c:/program files/beyond compare 3/bcomp.exe\" "$LOCAL" "$REMOTE" "$BASE" "$MERGED"

Then, I use $ git difftool to compare and $ git mergetool to merge.

About trustExitCode: For a custom merge command, specify whether the exit code of the merge command can be used to determine whether the merge was successful. If this is not set to true then the merge target file timestamp is checked and the merge assumed to have been successful if the file has been updated, otherwise the user is prompted to indicate the success of the merge.

wonea
  • 3,987
  • 17
  • 71
  • 134
yehnan
  • 4,922
  • 6
  • 30
  • 37
  • +1 Thanks, working for me on W7 x64, cygwin, git 1.7.6.msysgit. I had to adjust the path of course. – johnny Aug 19 '11 at 08:10
  • @yehnan - What is the second "$MERGED" for at the end of the merge command line ? – Adrian Russell Aug 23 '11 at 02:21
  • 12
    I'm running in windows 7 with a mingw git shell. I had to use a linux style path `/c/program files` instead of `c:/program files`. Also I removed the `"$(cygpath -w $LOCAL)"` and just used `"$LOCAL"`. That seemed to do the trick. – Landon Poch Aug 30 '12 at 04:57
  • 5
    As @pClass mentions below, "bc3" is now an internal tool in newer versions of git. You should use a unique name, such as "beyondcompare3" – Scott Wegner Oct 26 '12 at 16:46
  • 4
    GitHub Shell (on Windows 8) told me `bcompare: command not found`- until I changed the NAME of the tool from `bc3` to something else (like `abc3`). I guess that some internal Github setting interfered. Also, I removed the `"$(cygpath -w $LOCAL)"` part and replaced it with `"$LOCAL"`. Now it works just fine. Thanks! – Felix Alcala Nov 29 '12 at 21:17
  • Yup do not use "bc3" the name is internal, so the cmd in gitconfig is ignored. Cygwin's git is still 1.7.9, maybe newer versions fix the internal cmd for bc3 to something that works. – dashesy Jul 08 '13 at 21:11
  • 1
    This was buggy for me when looking at diff between two commits. Here is a better solution: http://blog.kifaru.be/2011/07/how-to-configure-git-on-windows-under-cygwin-to-use-beyond-compare-3/ – balajimc55 Sep 27 '16 at 01:04
  • 2
    I also found this article: http://www.scootersoftware.com/support.php?zz=kb_vcs – Guy Avraham Nov 05 '16 at 09:29
28

Thanks to @dahlbyk, the author of Posh-Git, for posting his config as a gist. It helped me resolve my configuration issue.

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    cmd = \"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\"
[merge]
    tool = bc3
[mergetool]
    prompt = false
    keepBackup = false
[mergetool "bc3"]
    cmd = \"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
    trustExitCode = true
[alias]
    dt = difftool
    mt = mergetool
Mike Cole
  • 13,228
  • 24
  • 106
  • 187
Nick Josevski
  • 3,976
  • 3
  • 41
  • 63
  • I tried this answer and was unable to diff, maybe I'm doing it wrong. – Epu Mar 19 '12 at 23:11
  • 1
    @Epu did you confirm your paths are the same on your machine? And it is Beyond Compare 3, not an older v2 or something? – Nick Josevski Mar 22 '12 at 06:28
  • I confirmed the paths are the same, and that it's bc3. – Epu Mar 23 '12 at 00:32
  • 1
    Funny thing is, 'git difftool file.txt' and 'git mergetool file.txt' are working ok, so I switched to those. But 'git diff file.txt' is now busted (before it used to show me the default console diff). Now it gives me 'error: cannot spawn bc3: No such file or directory\nexternal diff died, stopping at file.txt' – Epu Mar 23 '12 at 00:39
  • 1
    Just in case anyone faces the same problem I did (unrecognized .gitconfig after editing it) I had to add the path as follows: `cmd = 'C:\\Program Files\\Beyond Compare 4\\BCompare.exe' \"$LOCAL\" \"$REMOTE\"` – sebagomez Aug 24 '16 at 19:03
  • it seems new version of git in MSWindos can use `${LOCAL}` instead of `$LOCAL` as variable – YChi Lu Dec 07 '17 at 14:48
20

Run these commands for Beyond Compare 2:

git config --global diff.tool bc2
git config --global difftool.bc2.cmd "\"c:/program files (x86)/beyond compare 2/bc2.exe\" \"$LOCAL\" \"$REMOTE\""
git config --global difftool.prompt false

Run these commands for Beyond Compare 3:

git config --global diff.tool bc3
git config --global difftool.bc3.cmd "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
git config --global difftool.prompt false

Then use git difftool

sebagomez
  • 9,029
  • 6
  • 48
  • 84
user
  • 15,863
  • 15
  • 90
  • 110
  • 1
    Is Beyond Compare 4 supported? – Danijel Jan 23 '19 at 12:40
  • 3
    @Danijel the [official doc](http://www.scootersoftware.com/support.php?zz=kb_vcs#gitlinux) stated in @Daniel Magnussons answer states `Note: Use bc3 on the command line for both BC version 3 and 4` – BNT Feb 12 '19 at 10:06
10

Official documentation worked for me

Daniel Magnusson
  • 8,951
  • 2
  • 36
  • 43
6

Here is my config file. It took some wrestling but now it is working. I am using windows server, msysgit and beyond compare 3 (apparently an x86 version). Youll notice that I dont need to specify any arguments, and I use "path" instead of "cmd".

[user]
        name = PeteW
        email = petew@petew.com
[diff]
        tool = bc3
[difftool]
        prompt = false
[difftool "bc3"]
        path = /c/Program Files (x86)/Beyond Compare 3/BComp.exe
[merge]
        tool = bc3
[mergetool]
        prompt = false
        keepBackup = false
[mergetool "bc3"]
        path = /c/Program Files (x86)/Beyond Compare 3/BComp.exe
        trustExitCode = true
[alias]
        dt = difftool
        mt = mergetool
nachonachoman
  • 702
  • 1
  • 11
  • 28
5

The Beyond Compare support page is a bit brief.

Check my diff.external answer for more (regarding the exact syntax)

Extract:

$ git config --global diff.external <path_to_wrapper_script>

at the command prompt, replacing with the path to "git-diff-wrapper.sh", so your ~/.gitconfig contains

-->8-(snip)--
[diff]
    external = <path_to_wrapper_script>
--8<-(snap)--

Be sure to use the correct syntax to specify the paths to the wrapper script and diff tool, i.e. use forward slashed instead of backslashes. In my case, I have

[diff]
    external = c:/Documents and Settings/sschuber/git-diff-wrapper.sh

in .gitconfig and

"d:/Program Files/Beyond Compare 3/BCompare.exe" "$2" "$5" | cat

in the wrapper script.


Note: you can also use git difftool.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
4

it looks like BC3 only supports 3 way merge for PRO Edition. http://www.scootersoftware.com/moreinfo.php?zz=kb_editions

Mark Conway
  • 343
  • 1
  • 3
  • 10
3

Please notice you make a wrong path of $2. because you are under Cygwin but BC3 not, so you should specify a full path for it. such as "d:/cygwin$2"

Please refer my git-diff-wrapper.sh here:

$ cat ~/git-diff-wrapper.sh
#!/bin/sh
echo $2
echo $5
/cygdrive/c/Program\ Files\ \(x86\)/Beyond\ Compare\ 3/BCompare.exe "d:/programs/cygwin$2" "$5"

Good luck.

z33
  • 1,143
  • 13
  • 24
3

Update for BC4 64bit: This works for Git for Windows v.2.16.2 and Beyond Compare 4 - v.4.2.4 (64bit Edition)

I manually edited the .gitconfig file located in my user root "C:\Users\MyUserName" and replaced the diff/difftool and merge/mergetool tags with

[diff]
  tool = bc
[difftool "bc"]
  path = 'C:/Program Files/Beyond Compare 4/BComp.exe'
[difftool "bc"]
  cmd = \"C:/Program Files/Beyond Compare 4/BComp.exe\" \"$LOCAL\" \"$REMOTE\"
[difftool]
  prompt = false
[merge]
  tool = bc
[mergetool "bc"]
  path = 'C:/Program Files/Beyond Compare 4/BComp.exe'
[mergetool "bc"]
  cmd = \"C:/Program Files/Beyond Compare 4/BComp.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"
mitaka
  • 2,069
  • 1
  • 27
  • 30
3

If you are running windows 7 (professional) and Git for Windows (v 2.15 or above), you can simply run below command to find out what are different diff tools supported by your Git for Windows

git difftool --tool-help

You will see output similar to this

git difftool --tool=' may be set to one of the following:
vimdiff vimdiff2 vimdiff3

it means that your git does not support(can not find) beyond compare as difftool right now.

In order for Git to find beyond compare as valid difftool, you should have Beyond Compare installation directory in your system path environment variable. You can check this by running bcompare from shell(cmd, git bash or powershell. I am using Git Bash). If Beyond Compare does not launch, add its installation directory (in my case, C:\Program Files\Beyond Compare 4) to your system path variable. After this, restart your shell. Git will show Beyond Compare as possible difftool option. You can use any of below commands to launch beyond compare as difftool (for example, to compare any local file with some other branch)

git difftool -t bc branchnametocomparewith -- path-to-file
or 
git difftool --tool=bc branchnametocomparewith -- path-to-file

You can configure beyond compare as default difftool using below commands

   git config --global diff.tool bc

p.s. keep in mind that bc in above command can be bc3 or bc based upon what Git was able to find from your path system variable.

sarabdeep singh
  • 788
  • 1
  • 10
  • 15
1

The difference is in the exe being called: set it up to call bcomp.exe and it'll work fine. Configure your environment to call bcompare.exe and you'll end up with the side of the comparison taken from your revision system being empty.

rrozema
  • 141
  • 4
1

Run these commands for Beyond Compare 3(if the BCompare.exe path is different in your system, please replace it according to yours):

git config --global diff.tool bc3
git config --global difftool.bc3.cmd "\"c:/program files (x86)/beyond compare 3/BCompare.exe\" \"$LOCAL\" \"$REMOTE\""
git config --global difftool.prompt false

Then use git difftool

Jerry Z.
  • 1,891
  • 1
  • 20
  • 27
1

http://rubenlaguna.com/wp/2010/08/05/visual-difftool-cygwin-git/ has a solution that I adopted to work for BeyondCompare: http://gist.github.com/564573

Vincent Scheib
  • 13,630
  • 7
  • 56
  • 74
1

Windows 10, Git v2.13.2

My .gitconfig. Remember to add escape character for '\' and '"'.

[diff]
    tool = bc4
[difftool]
    prompt = false
[difftool "bc4"]
    cmd = \"C:\\Program Files\\Beyond Compare 4\\BCompare.exe\" \"$LOCAL\" \"$REMOTE\"
[merge]
    tool = bc4
[mergetool "bc4"]
    path = C:\\Program Files\\Beyond Compare 4\\BCompare.exe

You may reference setting up beyond compare as difftool for using git commands to config it.

zhangyu12
  • 125
  • 1
  • 3
  • Hi, I had a similar script and it failed until I switched to C:\\Program Files\\Beyond Compare 4\\BComp.exe. With BCompare.exe the temporary file was deleted before it could be compared, so I only saw the latest file, no checked-in version. – gabriel Jan 06 '20 at 22:43
1

With later versions of Git and Beyond Compare than what OP had, the below is what worked for me:

  • Git for Windows - v.2.22.0
  • Beyond Compare 4 - v.4.2.10 (64-bit Edition)

Config file to be edited: %USERPROFILE%\.gitconfig

Replace the diff/difftool and merge/mergetool tags with

[diff]
    tool = bc4
[difftool]
    prompt = false
[difftool "bc4"]
    cmd = \"c:/program files/beyond compare 4/bcomp.exe\" "$LOCAL" "$REMOTE"
[merge]
    tool = bc4
[mergetool]
    prompt = false
[mergetool "bc4"]
    trustExitCode = true
    cmd = \"c:/program files/beyond compare 4/bcomp.exe\" "$LOCAL" "$REMOTE" "$BASE" "$MERGED"
0

For whatever reason, for me, the tmp file created by git diff was being deleted before it opened in beyond compare. I had to copy it out to another location first.

cp -r $2 "/cygdrive/c/temp$2"
cygstart /cygdrive/c/Program\ Files\ \(x86\)/Beyond\ Compare\ 3/BCompare.exe "C:/temp$2" "$5"
Dustin
  • 3,455
  • 4
  • 24
  • 32
0

For MAC after doing lot of research it worked for me..! 1. Install the beyond compare and this will be installed in below location

/Applications/Beyond\ Compare.app/Contents/MacOS/bcomp

Please follow these steps to make bc as diff/merge tool in git http://www.scootersoftware.com/support.php?zz=kb_mac

Sreedhar GS
  • 2,461
  • 1
  • 19
  • 26
0

For git version 2.15.1.windows.2 with BC2.exe.

The config below finally works on my machine.

[difftool "bc2"] cmd = \"c:/program files/beyond compare 2/bc2.exe\" ${LOCAL} ${REMOTE}

YChi Lu
  • 79
  • 2
  • 6
0

Worked for me for Windows 10

Run in git terminal,

git config --global diff.tool bc3
git config --global difftool.bc3.path "c:/program files/beyond compare 4/bcomp.exe"
git config --global merge.tool bc3
git config --global mergetool.bc3.path "c:/program files/beyond compare 4/bcomp.exe"
Sazzad Hissain Khan
  • 29,428
  • 20
  • 134
  • 192