tortoisegit-Windows Git Bash可以将TortoiseMerge用作difftool吗?

我刚刚开始使用Git。 我想将TortoiseMerge用作difftool和mergetool。

在我的个人用户目录中的.gtconfig中,有以下部分。 我已经删除了该问题的用户和颜色部分。

[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\"

如果我在Git Bash提示符下键入tortoisemerge,则会加载它。 众所周知,它正在路上。 但是,如果键入命令,则会出现以下错误。

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 *)
$ 

我不了解要执行此工作吗?Tortoisemerge与TortoiseSVN一起安装。

5个解决方案
65 votes

以下设置对我来说很好用。 但是,我使用的是TortoiseGit而不是TortoiseSVN。 注意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"
Klas Mellbourn answered 2020-06-26T23:19:14Z
7 votes

为了正确处理带空格的文件名,您应该将@melbourn答案的最后一行更改为

cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$REMOTE" -mine "$LOCAL" -merged "$MERGED"
jwg answered 2020-06-26T23:19:34Z
0 votes

Klas Mellbourn的好答案! 节省了我很多时间。一个缺点是,在difftool命令执行期间,存储库中的新git add .git difftool --staged文件将不会显示。 没有什么可比拟的! 这是我在此之上所做的:(灵感来自我同事的回答)。

  1. git difftool --staged目录中创建一个名为git add .的文件(在bash中执行git difftool)。 顾名思义,将其保留为空。
  2. git difftool --staged目录中创建另一个名为git add .的文件,其内容如下

:

#!/bin/sh
# $LOCAL $REMOTE seem to be swapped
# $1 is $LOCAL
# $2 is $REMOTE

difftool='/c/Program Files/TortoiseGit/bin/TortoiseGitMerge.exe'
NULL="/dev/null"
empty="C:/home/empty.empty"

if [ "$1" == "$NULL" ]; then
    echo "Added: " "$2"
    "$difftool" /base:"$empty" /mine:"$2" /readonly:"$empty"
elif [ "$2" == "$NULL" ]; then
    echo 'Removed: ' "$1"
    "$difftool" /base:"$1" /readonly:"$1" /mine:"$empty"
else
    echo 'Modified' "$2"
    "$difftool" /base:"$1" /basename:"$1" /readonly:"$1" /mine:"$2" /minename:"$2"
fi

# Checkout https://tortoisegit.org/docs/tortoisegitmerge/tme-automation.html for more
  1. 修改您的.gitconfig文件(答案的第11行)

    git add .

现在,这将使difftool引用tortoisediff.sh而不是直接打开应用程序。

  1. 请记住:您必须先运行git add .,然后再运行git difftool --staged,而不是仅运行git difftool
ThePatelGuy answered 2020-06-26T23:20:25Z
0 votes
[diff]
  tool = tortoisediff
[difftool]
  prompt = false
[merge]
  tool = tortoisemerge
[mergetool]
  prompt = false
  keepBackup = false
[difftool "tortoisediff"]
  cmd = \""C:/Users/$USER/Desktop/TortoiseMerge.exe"\" -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"
[mergetool "tortoisemerge"]
  cmd = \""C:/Users/$USER/Desktop/TortoiseMerge.exe"\" -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"

使用TortoiseMerge 1.6.7(Portable)对我有用

smooth_smoothie answered 2020-06-26T23:20:45Z
0 votes

重新设定基准时,强烈建议使用开关$theirs$mine,因为在合并和重新合并基准时,它是不同的。 在这里检查:

git中“我们的”和“他们的”的确切含义是什么?

因此,如果仅像我一样使用mergetool进行基准调整,请执行以下操作:

[mergetool "tortoisemerge"]
cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$LOCAL" -mine "$REMOTE" -merged "$MERGED"
WesternGun answered 2020-06-26T23:21:14Z
translate from https://stackoverflow.com:/questions/16493368/can-tortoisemerge-be-used-as-a-difftool-with-windows-git-bash