Git Diff with Beyond Compare
Asked Answered
O

21

137

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
Oyler answered 15/1, 2010 at 4:21 Comment(1)
If you got to this question but you need a solution for mac [like me] you can check out this answer https://mcmap.net/q/12821/-git-diff-with-beyond-compareWalterwalters
I
163

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.

See also Directory Diff with working directory (local files).

Incorporated answered 3/8, 2010 at 10:10 Comment(8)
+1 Thanks, working for me on W7 x64, cygwin, git 1.7.6.msysgit. I had to adjust the path of course.Oxymoron
@Incorporated - What is the second "$MERGED" for at the end of the merge command line ?Byer
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.Soloist
As @pClass mentions below, "bc3" is now an internal tool in newer versions of git. You should use a unique name, such as "beyondcompare3"Spotter
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!Estren
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.Gillead
This was buggy for me when looking at diff between two commits. Here is a better solution: blog.kifaru.be/2011/07/…Hay
I also found this article: scootersoftware.com/support.php?zz=kb_vcsIrradiate
T
32

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
Truda answered 1/3, 2012 at 22:52 Comment(6)
I tried this answer and was unable to diff, maybe I'm doing it wrong.Romy
@Romy did you confirm your paths are the same on your machine? And it is Beyond Compare 3, not an older v2 or something?Truda
I confirmed the paths are the same, and that it's bc3.Romy
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'Romy
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\"Ejaculation
it seems new version of git in MSWindos can use ${LOCAL} instead of $LOCAL as variableSettee
E
23

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

Estuary answered 7/6, 2011 at 13:56 Comment(3)
Is Beyond Compare 4 supported?Dulse
@Dulse the official doc stated in @Daniel Magnussons answer states Note: Use bc3 on the command line for both BC version 3 and 4Notability
this doesn't seem to work for windowsSynoptic
T
14

Official documentation worked for me

Temperamental answered 16/5, 2012 at 9:45 Comment(1)
Thanks man for pointing me to official doc!!! at least it specifies what diff config needed for GIT vs GitHubMiculek
P
11

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"
Perturb answered 9/4, 2021 at 19:28 Comment(0)
W
7

To use beyond compare in MAC OSX you need to do the following: Install beyond compare command-line tools from the menu:

enter image description here

Then you need to run those commands:

git config --global diff.tool bc3

git config --global merge.tool bc3
git config --global mergetool.bc3.trustExitCode true

After that, you could run git mergetool in the folder with git conflict and BC will work as expected

Walterwalters answered 21/10, 2021 at 9:9 Comment(0)
S
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 = [email protected]
[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
Sewole answered 10/10, 2012 at 13:39 Comment(0)
M
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.

Mavismavra answered 15/1, 2010 at 6:51 Comment(0)
C
5

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

Cerveny answered 19/11, 2013 at 1:39 Comment(0)
B
5

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\"
Bootstrap answered 26/3, 2018 at 16:45 Comment(1)
If you could explain your answer that would be appreciatedSynoptic
A
5

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.

Alain answered 3/5, 2018 at 17:20 Comment(0)
A
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.

Analects answered 6/4, 2010 at 4:49 Comment(1)
You really should use cygpath for this; e.g. bcompare.exe $(cygpath -w $2). Cheers.Lymphoid
D
3

Worked for me on 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"
Dishcloth answered 5/5, 2021 at 6:44 Comment(2)
uhh.. and then what?Synoptic
thanks , it worked for me -Beyond compare 4 in windows 10Cordell
F
2

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

Fold answered 7/4, 2015 at 13:15 Comment(0)
F
2

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.

Fichtean answered 20/12, 2018 at 6:54 Comment(2)
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.Chiasma
forwardslash should also work in place of 2 backslashesSynoptic
S
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

Sybyl answered 3/9, 2010 at 21:45 Comment(0)
G
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.

Glob answered 3/11, 2014 at 11:23 Comment(0)
M
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"
Mccabe answered 28/5, 2010 at 12:15 Comment(0)
I
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

Itinerancy answered 28/11, 2015 at 3:56 Comment(0)
S
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}

Settee answered 6/12, 2017 at 18:18 Comment(0)
S
0

If you don't want to muck around with config files, you can just use difftool's --extcmd.

So when I do compares on my computer, I just paste this into my VSCode terminal:

git difftool  --dir-diff --no-symlinks --extcmd "C:\Program Files\Beyond Compare 4\bcomp.exe" HEAD..master

No config required.

Synoptic answered 13/2, 2023 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.