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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16493368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:30:51  来源:igfitidea点击:

Can TortoiseMerge be used as a difftool with Windows Git Bash?

gittortoisegitgit-difftortoisegitmerge

提问by Rich Shealer

I'm just starting to work with Git. I would like to use TortoiseMerge as the difftool and mergetool.

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

In my .gtconfig in my personal user directory I have the following sections. I've removed the user and color sections for this question.

在我的个人用户目录中的 .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\"

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.

如果我在 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 *)
$ 

What am I not understanding to make this work? Tortoisemerge is installed with TortoiseSVN.

我有什么不明白的?Tortoisemerge 与 TortoiseSVN 一起安装。

回答by Klas Mellbourn

The following settings work fine for me. However, I am using TortoiseGit not TortoiseSVN. Notice the difference in the parameters for diff.

以下设置对我来说很好。但是,我使用的是 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"

回答by jwg

So that filenames with spaces are handled correctly, you should change the last line of @melbourn's answer to

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

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

回答by ThePatelGuy

Great answer by Klas Mellbourn! Saved me a lotta time. One shortcoming is, newly Addedor Removedfiles in the repository will not show up during the difftool command execution. There's nothing to compare them to! Here's what I did on top of this: (Inspired by my co-worker's answer).

Klas Mellbourn 的精彩回答!为我节省了很多时间。一个缺点是,在 difftool 命令执行期间,存储库中的新文件AddedRemoved文件不会出现。没有什么可比的!这是我在此基础上所做的:(受我同事的回答启发)。

  1. Create a file named empty.emptyin $Homedirectory (execute start ~in your bash). And as the name suggests, keep it empty.
  2. Create another file named tortoisediff.shin $Home/bindirectory with following content
  1. 创建一个empty.empty$Home目录中命名的文件(start ~在你的 bash 中执行)。顾名思义,将其留空。
  2. 使用以下内容创建另一个tortoisediff.sh$Home/bin目录中命名的文件

:

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

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

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

# Checkout https://tortoisegit.org/docs/tortoisegitmerge/tme-automation.html for more
  1. Modify your .gitconfig file (Line 11 of the answer)

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

  1. 修改您的 .gitconfig 文件(答案的第 11 行)

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

This would now make difftool refer to tortoisediff.sh instead of opening the application directly.

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

  1. Keep in mind:you'd have to run git add .followed by git difftool --stagedinstead of simply git difftool.
  1. 请记住:您必须运行git add .后跟git difftool --staged而不是简单地运行git difftool

回答by smooth_smoothie

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

This worked for me, using TortoiseMerge 1.6.7 (Portable)

这对我有用,使用 TortoiseMerge 1.6.7(便携式)

回答by WesternGun

When rebasing, I strongly recommend switch $theirsand $mine, because it is different when you merge and rebase-merge. Check here:

在变基时,我强烈建议使用 switch$theirs$mine,因为在合并和变基合并时它是不同的。检查这里:

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

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

So, if you only use mergetool to rebase like me, do:

所以,如果你像我一样只使用 mergetool 来变基,请执行以下操作:

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

回答by wellsantos

For using the TortoiseMerge with an existing TortoiseSVN installation in Windows:

要将 TortoiseMerge 与 Windows 中现有的 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"