本文介绍了使用Git + TortoiseMerge,由于路径名中有空格,无法将文件加载到TortoiseMerge中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Tortoise的DiffMerge工具来解决git合并冲突。



我拥有以下我的.gitconfig:

  [diff] 
工具= tortoisediff
[difftool]
提示符= false
[合并]
tool = tortoisemerge
[mergetool]
prompt = false
keepBackup = false
[difftooltortoisediff]
cmd = \c: / Program Files / TortoiseGIT / bin / TortoiseGitMerge.exe\-mine:$ REMOTE-base:$ LOCAL
[mergetooltortoisemerge]
cmd = \c :/ Program Files / TortoiseGIT / bin / TortoiseGitMerge.exe\-base:$ BASE-theirs:$ REMOTE-mine:$ LOCAL-merged:$ MERGED

TortoiseGit可以打开,但是当我尝试使用我的文件时,我收到一个错误消息:





位置的完整路径如下所示:

  C:\Users\Stream us \Documents\GitHub\StreamusServer\Streamus.Tests\Controller Tests\ErrorControllerTest.cs 

有可能使用Git和TortoiseMerge来支持这条路径吗?据我所知,我正在逃避路径。

解决方案

创建一个将启动TortoiseMerge的CMD文件:

  TortoiseMerge.exe -base:%1 -mine:%2  - 他们:%3  -  merged:%4 

然后在 .gitconfig 中设置mergetool:

  [合并] 
工具= mytool
[mergetoolmytool]
cmd = cmd / C tortoiseMerge -git.cmd$ BASE$ LOCAL$ REMOTE$ MERGED

背景:

Git内部使用sh的Windows版本。如果它启动了一个命令,它将正确处理文件名中的空格。如有必要,包含空格的参数将用引号括起来。但是我还没有找到一种方法来强制在一半的参数上进行字面引用。



TortoiseMerge期望参数如下所示: -mine: some path / some file.txt。如果 -mine 也包含在引号中,它将不起作用。



因此,我们可以创建一个批处理文件, > -mine:,但我们遇到了另一个bug:如果使用批处理文件作为命令,那么CMD文件将被 sh 而不是解析。 cmd ,所以我们用/ C开关显式调用cmd来执行命令。



还要注意,在批处理文件 %1 等会在它们周围引用引号,所以不要在批处理文件中添加另外一组引号。


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

解决方案

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.

这篇关于使用Git + TortoiseMerge,由于路径名中有空格,无法将文件加载到TortoiseMerge中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:18