Reproducing my answer from this thread which was more specific to setting beyond compare as diff tool for Git. All the details that I've shared are equally useful for any diff tool in general so sharing it here:
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
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:
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
The 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.