Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use BeyondCompare to see difference between files in GIT

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

like image 596
SharpCoder Avatar asked Mar 26 '14 08:03

SharpCoder


People also ask

How do I compare files in Beyond Compare?

To compare files in the Folder Compare like in the file viewers: In the Folder Compare, select Session | Session Settings and pick the Comparison tab. Enable the Compare contents option and make sure Rules-based comparison is enabled.

How do I compare three files in Beyond Compare?

If the main file and the other files are all located in the same folder, load the folder in the Folder Compare. Then select the main file and one of the other files. Right click and select Open to launch the two files in the Text Compare. Repeat for each file that must be compared to main.

How to enable beyond compare in Git?

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.

How do I compare two versions of a file in Git?

Comparing two file versions in your Git repository If you’re using Git and need to compare two recent versions of the same file, I can confirm that this git diff command works: git diff HEAD^ HEAD nodeBlog.scala.html That command compares the second-most recent version of the file (given by HEAD^) to the most recent version of the file (HEAD).

How to launch beyond compare as difftool in Git?

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

How to compare head and dirty files in Git?

The best way I found, aside of using a dedicated commit GUI, is to use git difftool -d - This opens your diff tool in directory comparison mode, comparing HEAD with current dirty folder. Show activity on this post. This shows a comparison using VI slit window in the terminal.


2 Answers

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

like image 82
SharpCoder Avatar answered Sep 18 '22 11:09

SharpCoder


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.

like image 27
RBT Avatar answered Sep 21 '22 11:09

RBT