Question

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 !!

Was it helpful?

Solution

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".

OTHER TIPS

I'll elaborate more to complement 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 file found in %userprofile% directory:

[diff]
    tool = bc3

%userprofile% is an environment variable which you can type on Run prompt and hit Enter to open the directory location where .gitconfig file is present.

That's it. This is all you required while setting up an already published version of any well-known comparison tool which is already known to Git like in this case 3rd version of Beyond Compare is known to Git.

Let's do a deep-dive now!

Additionally, you might be required to run the below command also:

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

Running this command is optional. It is required in some specialized cases only. We will know its reason in a short while from now.

Above command creates below entry in .gitconfig file:

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

The most important thing to know here is the key bc3. This is a well-known key to Git which maps to a particular version of a specific comparison tool available in market e.g. in this case bc3 corresponds to 3rd version of Beyond Compare tool. If you want to see complete list of the keys maintained by Git then run below comand on Git Bash command-line:

git difftool --tool-help

When we run above command then 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

While setting up a comparison tool for Git, we can use any of the above pre-existing keys based on the tool and its version you're using e.g. for Beyond Compare v1 we'll use the key bc, for Beyond Compare v3 we'll use the key bc3.

But in some cases, we might have to define a brand new key of our own e.g. let's say we're setting-up a brand new comparison tool which has just been released to market. For obvious reasons the current version of Git installed on your machine will not show any key corresponding to this new tool. Eventually Git will show it in a future release but not immediately. Similarly, this problem can occur for a newly released version of an existing tool also e.g. there is no key for Beyond Compare v4 in above list. So you are always free to map any tool to any of pre-existing keys or to a new custom key of your own.

Now let us understand below scenarios for while setting up a comparison tool which is:

  • A new version of an old tool has got released which is not mapped to any pre-defined keys in Git?

OR

  • Absolutely new in market

Like in my case, I had installed Beyond Compare v4. Beyond Compare tool is already known to Git but its version 4 release is not mapped to any of the existing keys. So we can follow any of the below approaches:

  1. Since no key exists in Git for Beyond Compare v4 so we can map it to the already existing key bc3 even though it is meant to be mapped to Beyond Compare v3. We can outsmart Git to save some effort.

    Now here is the answer to the question we left unanswered in the first paragraph - If you map any tool to the key which is already known to Git then you would not need to run the second command. This is because the tool's EXE location is already known to Git.

    But remember, this will work only when the EXE location of the tool doesn't change across versions. If Beyond Compare v3 and v4 have different install locations in %programfiles% directory then it becomes mandatory to run the second command.

    For e.g. if I had installed Beyond Compare v3 on my box then having below configuration in my .gitconfig file would have been sufficient to complete the setup process. This is based on the assumption that v3 and v4 will have same install path.

    [diff]
    tool = bc3
    

    But if we want to associate the non-default tool then we need to mention the path attribute separately so that Git will know the path of EXE from where it has to be launched. Below entry tells Git to launch Beyond Compare v4 instead. Note the EXE's path:

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

    Also, if we wanted we could have mapped Beyond Compare v4 to any of the pre-defined keys of other tools as well e.g. examdiff. Git won't stop you from doing this bad thing. Although we should not do so avoid a maintenance nightmare.

  2. Cleanest approach is to define a custom key. We can define a brand new key for any new comparison tool or a new version of an old tool. Like in my case I defined a new key bc4 as it is fairly intuitive. I could have named it foobaar.

    Now when the key is absolutely new, the setup process is slightly different. In this case you have to run two commands in all. But our second command will not be setting path of our new tool's EXE. Instead we have to set cmd attribute for our 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 maintenance issues in future.

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)

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"

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top