TortoiseMerge可以用作Windows Git Bash的difftool吗?

时间:2013-05-11 03:10:27

标签: git tortoisegit git-diff tortoisegitmerge

我刚刚开始与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一起安装。

6 个答案:

答案 0 :(得分:62)

以下设置适用于我。但是,我使用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"

答案 1 :(得分:7)

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

cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$REMOTE" -mine "$LOCAL" -merged "$MERGED"

答案 2 :(得分:0)

Klas Mellbourn的精彩回答!救了我很多时间。 一个缺点是,在difftool命令执行期间,存储库中的新AddedRemoved文件不会显示。没有什么可以比较它们!这是我在此基础上所做的: (灵感来自我的同事answer)。

  1. empty.empty目录中创建一个名为$Home的文件(在bash中执行start ~)。顾名思义,请保持空白。
  2. tortoisediff.sh目录中创建另一个名为$Home/bin的文件,其中包含以下内容
  3. #!/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行)

      cmd = tortoisediff.sh "$LOCAL" "$REMOTE"

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

      1. 请注意:您必须先运行git add .,然后git difftool --staged而不是git difftool

答案 3 :(得分:0)

[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(便携式)对我来说很有效

答案 4 :(得分:0)

重新定基时,强烈建议切换$theirs$mine,因为在合并和重新合并时它是不同的。检查这里:

What is the precise meaning of "ours" and "theirs" in git?

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

[mergetool "tortoisemerge"]
cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$LOCAL" -mine "$REMOTE" -merged "$MERGED"

答案 5 :(得分:0)

要在Windows中将TortoiseMerge与现有的TortoiseSVN安装一起使用:

[guitool "VisualDiff"]
    cmd = git difftool -y \"$FILENAME\"
    needsfile = yes
    noconsole = yes
[diff]
    tool = tortoisediff
[difftool]
    prompt = false
[merge]
    tool = tortoisemerge
[mergetool]
    prompt = false
    keepBackup = false
[difftool "tortoisediff"]
    cmd = \""W:/Programs/TortoiseSVN/bin/TortoiseMerge.exe"\" "/mine:$REMOTE" "/base:$LOCAL"
[mergetool "tortoisemerge"]
    cmd = \""W:/Programs/TortoiseSVN/bin/TortoiseMerge.exe"\" "/base:$BASE" "/theirs:$REMOTE" "/mine:$LOCAL" "/merged:$MERGED"