问题
I'm trying to use Tortoise's DiffMerge tool to resolve a git merge conflict.
I've got the following my my .gitconfig:
[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"
TortoiseGit opens fine, but when I try and work with my file I get an error:

The full path to the location looks like:
C:\Users\Streamus\Documents\GitHub\StreamusServer\Streamus.Tests\Controller Tests\ErrorControllerTest.cs
Is it possible to support this path using Git and TortoiseMerge? As far as I am aware I am properly escaping the path..
回答1:
create a CMD file which will launch TortoiseMerge:
TortoiseMerge.exe -base:%1 -mine:%2 -theirs:%3 -merged:%4
And set up your mergetool in .gitconfig
:
[merge]
tool = mytool
[mergetool "mytool"]
cmd = cmd /C tortoiseMerge-git.cmd "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
The background:
Git internally uses a Windows version of sh. If it launches a command it will handle spaces in file names correctly. Arguments containing spaces are wrapped in quotes if necessary. But I haven't found a way to force having a literal quote halfway an argument.
TortoiseMerge expects arguments to look like this: -mine:"some path/some file.txt"
. If -mine is also enclosed in the quotes it won't work.
So we can create a batch file which just sticks the -mine: in front of the path, but there we encounter another bug: if you use a batch file as command, then the CMD file gets parsed by sh instead of cmd, so we explicitly invoke cmd with the /C switch to execute a command.
Note also that in the batch file, %1
etc. will have quotes around them, so don't add another set of quotes in the batch file.
来源:https://stackoverflow.com/questions/22232659/using-git-tortoisemerge-failing-to-load-file-into-tortoisemerge-because-of-sp