16

Before I commit my changes, I want to see the difference using BeyondCompare in GIT. How can I configure BeyondCompare to see difference in my files.

I looked at this link but it did not help.

BeyondCompare is installed at this location in my system: C:\program files\Beyond Compare\BCompare.exe

I ran following two commands:

 git config --global merge.tool bc

git config --global mergetool.bc.path "C:\program files\Beyond Compare\BCompare.exe"

I am using GIT on Windows 7.

Thanks !!

SharpCoder
  • 17,049
  • 41
  • 140
  • 238
  • Related post - How to [configure a diff tool in Git in general](https://stackoverflow.com/q/6412516/465053). – RBT Apr 05 '18 at 23:47

5 Answers5

20

This link tells the way to set up BeyondComapre as the diff tool in git

git config --global diff.tool bc3
git config --global difftool.bc3.path "c:/program files/beyond compare 3/bcomp.exe"

To launch a diff using Beyond Compare, use the command "git difftool foofile.txt".

JohnD
  • 3,846
  • 1
  • 28
  • 40
SharpCoder
  • 17,049
  • 41
  • 140
  • 238
  • 9
    +1, one thing to note for BC4 users is that you still need to give bc3 as the tool name. That's because git has a set of allowable names for external diff tools. You can see those with `git difftool --tool-help` – zx81 Nov 10 '16 at 06:33
10

I'll just elaborate more on @SharpCoder's accepted answer.

The first command that we run is as below:

git config --global diff.tool bc3

The above command creates below entry in .gitconfig found in %userprofile% directory:

[diff]
    tool = bc3

Then you run below command (Running this command is redundant in this particular case and is required in some specialized cases only. You will know it in a short while):

git config --global difftool.bc3.path "c:/program files/beyond compare 3/bcomp.exe"

Above command creates below entry in .gitconfig file:

[difftool "bc3"]
    path = c:/program files/Beyond Compare 3/bcomp.exe

The thing to know here is the key bc3. This is a well known key to git corresponding to a particular version of well known comparison tools available in market (bc3 corresponds to 3rd version of Beyond Compare tool). If you want to see all pre-defined keys just run git difftool --tool-help command on git bash. It returns below list:

vimdiff
vimdiff2
vimdiff3
araxis
bc
bc3
codecompare
deltawalker
diffmerge
diffuse
ecmerge
emerge
examdiff
gvimdiff
gvimdiff2
gvimdiff3
kdiff3
kompare
meld
opendiff
p4merge
tkdiff
winmerge
xxdiff

You can use any of the above keys or define a custom key of your own. If you want to setup a new tool altogether(or a newly released version of well-known tool) which doesn't map to any of the keys listed above then you are free to map it to any of keys listed above or to a new custom key of your own.

What if you have to setup a comparison tool which is

  • Absolutely new in market

OR

  • A new version of an existing well known tool has got released which is not mapped to any pre-defined keys in git?

Like in my case, I had installed beyond compare 4. beyond compare is a well-known tool to git but its version 4 release is not mapped to any of the existing keys by default. So you can follow any of the below approaches:

  1. I can map beyond compare 4 tool to already existing key bc3 which corresponds to beyond compare 3 version. I didn't have beyond compare version 3 on my computer so I didn't care. If I wanted I could have mapped it to any of the pre-defined keys in the above list also e.g. examdiff.

    If you map well known version of tools to appropriate already existing/well- known key then you would not need to run the second command as their install path is already known to git.

    For e.g. if I had installed beyond compare version 3 on my box then having below configuration in my .gitconfig file would have been sufficient to get going:

    [diff]
    tool = bc3
    

    But if you want to change the default associated tool then you end up mentioning the path attribute separately so that git gets to know the path from where you new tool's exe has to be launched. Here is the entry which foxes git to launch beyond compare 4 instead. Note the exe's path:

    [difftool "bc3"]
    path = c:/program files/Beyond Compare 4/bcomp.exe
    
  2. Most cleanest approach is to define a new key altogether for the new comparison tool or a new version of an well known tool. Like in my case I defined a new key bc4 so that it is easy to remember. In such a case you have to run two commands in all but your second command will not be setting path of your new tool's executable. Instead you have to set cmd attribute for your new tool as shown below:

    git config --global diff.tool bc4
    
    git config --global difftool.bc4.cmd "\"C:\\Program Files\\Beyond Compare 4\\bcomp.exe\" -s \"\$LOCAL\" -d \"\$REMOTE\""
    

    Running above commands creates below entries in your .gitconfig file:

    [diff]
    tool = bc4
    [difftool "bc4"]
    cmd = \"C:\\Program Files\\Beyond Compare 4\\bcomp.exe\" -s \"$LOCAL\" -d \"$REMOTE\"
    

I would strongly recommend you to follow approach # 2 to avoid any confusion for yourself in future.

RBT
  • 21,293
  • 19
  • 144
  • 210
  • 1
    You _can_ use keys which are not part of the list returned by `git difftool --tool-help` so long as your define them first. For example, I use Semantic Merge so I have the following configuration: `[diff] tool = semanticmerge [difftool "semanticmerge"] cmd = \"C:\\Users\\chris\\AppData\\Local\\semanticmerge\\semanticmergetool.exe\" -s \"$LOCAL\" -d \"$REMOTE\"` – Chris Seed Aug 09 '17 at 08:25
  • ohh. I clearly remember trying what you've suggested. It gives error - `git config option diff.tool set to unknown tool`. But, I see you are using a different attribute named `cmd` while I am using `path`. In fact when I had hit across this error initially, it seemed like a very bad limitation. – RBT Aug 09 '17 at 09:26
  • @ChrisSeed you did the settings directly by editing the `.gitconfig` file or it is also possible to set this `cmd` configuration from command line also. I tried running command like this - `$ git config --global difftool.semanticmerge.cmd "C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe" -s "$LOCAL" -d "$REMOTE"` but it doesn't succeed. – RBT Aug 09 '17 at 09:35
  • Directly editing the config file (or the Semantic Merge installer did it for me). Most of the examples I've seen for setting up merge/diff tools show you the final output of `.gitconfig` so I generally just edit it directly; not tried it via `git config` I'm afraid. – Chris Seed Aug 09 '17 at 13:37
  • 1
    You _can_ do it via git config, you just need more quotes and escaping: `git config --global difftool.semanticmerge.cmd "\"C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" -s \"\$LOCAL\" -d \"\$REMOTE\""` – Chris Seed Aug 09 '17 at 13:37
  • Thanks a lot @ChrisSeed for all the knowledge. I finally got it working through command line also through your advice. I've updated my post to accommodate your feedback. Please let me know if I'm still missing anything. – RBT Aug 10 '17 at 03:03
2

Beyond compare is a mergetool and a diff tool. I have it for both operations anyway. When I want to see the differences between my current state and the last commited I write

    git diff 

for a fast text output and small changes and

   git difftool

for changes in multiple files. Also keep in mind that you can do a git log, copy the first part of your commit's hash value and do a

   git difftool (commit1) (commit2)

and compare all the files one after another (very productive and useful)

user1941126
  • 319
  • 1
  • 7
1

The instruction refered in the question worked last time I tried it, but I think you should run the commands in git bash and replace backslash in your path with forward slash.

git config --global merge.tool bc
git config --global mergetool.bc.path "C:/program files/Beyond Compare/BCompare.exe"
Simson
  • 3,066
  • 2
  • 21
  • 34
  • Thank you for reply. I tried your solution and it did not helped. I think the problem is we are specifying merge tool as BeyondComapre when we should be specifying BeyondCompare as the git diff tool . – SharpCoder Mar 26 '14 at 09:38
  • Weird, is your path correct and did it use / ? Try to set it up as diff tool too and see if that works. – Simson Mar 26 '14 at 09:46
  • Yes the path is correct. Is there any command to set up diff tool ? – SharpCoder Mar 26 '14 at 10:21
  • We can set diff tool as well. I was using git diff command & was hoping beyondCompare will launch but the actual command is `git difftool foofile.txt`. Use this link for more information "http://www.scootersoftware.com/support.php?zz=kb_vcs#gitwindows" . Thank you for the help. – SharpCoder Mar 26 '14 at 10:38
  • I think you need BeyondCompare Pro for to use the merge feature. – Mithril Apr 27 '16 at 06:10
0

If you are using Windows with WSL you can configure git to use your windows diff and merge tools in both worlds (Linux and Windows).

Setting up .gitconfig for windows is trivial but for Linux it is not. In my case I'm using Beyond Compare 3 (installed on Windows) and I have git configured in both, Windows and Linux, to use it as merge and diff tools.

I'll describe how I have my .gitconfig file configured in Linux. I'm using Ubuntu 20.04 but I guess it should be similar in other distributions. Luckily, no extra setup is required for the merge tool.

Configuring the merge tool

This part is pretty simple, you just need to add the following configuration in your .gitconfig file:

[merge]
    tool = bc
[mergetool]
    keepBackup = false
    trustExitCode = true
    prompt = false
[mergetool "bc"]
    path = /mnt/c/Program Files/Beyond Compare 4/bcomp.exe

There are a few extra optional settings but you can simply use it as I do One important thing to notice is that mergetool path. In my case I have Beyond compare installed in my c windows drive

Configuring the diff tool

For the diff tool things are a little more complicated and it requires a little more effort. The first thing you need to do is to create a separate executable. I'm not sure why this is required but git docs say this so.

In my case, I created my own executable at \\wsl.localhost\Ubuntu\home\{your-user}\.local\bin\extDiff and I gave it execution permissions chmod +x extDiff

This are its contents

#bin/bash
"/mnt/c/Program Files/Beyond Compare 4/bcomp.exe" "$1" "$2"

The only missing thing is to update .gitconfig file

[diff]
    tool = bc
[difftool]
    prompt = false
[difftool "bc"]
    cmd = /home/{your-user}/.local/bin/extDiff `wslpath -m "$REMOTE"`  `wslpath -m "$LOCAL"` 

wslpath is a program that converts linux to windows paths and viceversa. In this case I'm calling my previously defined executable passing the $REMOTE and $LOCAL vars provided by git during execution. Notice that I have to convert the current Linux paths into Windows paths

Now everything is set up. Next time you run git difftool or git mergetool Windows' Beyond Compare will be launched.

Pato Loco
  • 1,095
  • 1
  • 9
  • 27