Can TortoiseMerge be used as a difftool with Windows Git Bash?
I'm just starting to work with Git. I would like to use TortoiseMerge as the difftool and mergetool.
In my $HOME/.gitconfig
I have the following sections. I've removed the user and color sections for this question.
[merge]
tool = tortoisemerge
[mergetool "tortoisemerge"]
cmd = \"TortoiseMerge.exe\" -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"
[diff]
tool = tortoisemerge
[difftool "tortoisemerge"]
cmd = \"TortoiseMerge.exe\" -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"
If I type tortoisemerge at the Git Bash prompt it loads. It is known to be on the path. But if I type the command I get the following error.
Rich:mygittest (master *)
$ git difftool
error: 'tortoisemerge' can only be used to resolve merges
merge tool candidates: kompare emerge vimdiff
No known merge resolution program available.
external diff died, stopping at readme.txt.
Rich:mygittest (master *)
$
What am I not understanding to make this work? Tortoisemerge is installed with TortoiseSVN.
The following settings work fine for me. However, I am using TortoiseGit not TortoiseSVN. Notice the difference in the parameters for diff.
[diff]
tool = tortoisediff
[difftool]
prompt = false
[merge]
tool = tortoisemerge
[mergetool]
prompt = false
keepBackup = false
[difftool "tortoisediff"]
cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -mine "$REMOTE" -base "$LOCAL"
[mergetool "tortoisemerge"]
cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$REMOTE" -mine "$LOCAL" -merged "$MERGED"
So that filenames with spaces are handled correctly, you should change the last line of @melbourn's answer to
cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$REMOTE" -mine "$LOCAL" -merged "$MERGED"
This is a simpler way, just run these commands in git bash:
git config --global merge.tool tortoisemerge
git config --global diff.tool tortoisediff
git config --global difftool.tortoisediff.cmd "TortoiseGitMerge \$LOCAL \$REMOTE"
It's done.
----for futher reading----
There are other settings you may need:
# you may want to disable prompt or merge backup
git config --global mergetool.keepBackup false
git config --global difftool.prompt false
git config --global mergetool.prompt false
# set the path only when it's not found in system path
git config --global mergetool.tortoisemerge.path "C:\Program Files\TortoiseGit\bin\TortoiseGitMerge.exe"
git config --global difftool.tortoisdiff.path "C:\Program Files\TortoiseGit\bin\TortoiseGitMerge.exe"
To set the mergetool, you just need to set the right mergetool name. It's official supported.
Git for windows installer includes a shell file for running tortoisegitmerge as a merge tool. It locates at C:\Program Files\Git\mingw64\libexec\git-core\mergetools
. (Git provides 4 variables for merging: $BASE $LOCAL $REMOTE $MERGED
, you can check them in the shell file.)
You can check all supported merge/diff tools supported on your machine with the command:
git difftool --tool-help
git mergetool --tool-help
Run tortoisegitmerge as git diff tool is not official supported by git, maybe it's because this tool doesn't support directory compare (git difftool -d
). So you need to config the difftool cmd to use it as a git difftool.
The tortoisegitmerge tool has a manual at:
https://tortoisegit.org/docs/tortoisegitmerge/tme-automation.html
You can find the simplest way to do file diff is:TortoiseGitMerge BaseFilePath MyFilePath [ TheirFilePath ]