TortoiseMerge可以作为Windows Git Bash的比较工具使用吗?

carvr3hs  于 2022-11-20  发布在  Git
关注(0)|答案(7)|浏览(199)

我刚刚开始使用Git。我想使用TortoiseMerge作为区分工具和合并工具。
在我的$HOME/.gitconfig中,我有以下部分。我已经删除了这个问题的用户和颜色部分。

[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。

mpbci0fu

mpbci0fu1#

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

lqfhib0f2#

为了正确处理带有空格的文件名,您应该将@梅尔伯恩的答案的最后一行改为

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

to94eoyn3#

这是一个更简单的方法,只需在git bash中运行以下命令:

git config --global merge.tool tortoisemerge

git config --global diff.tool tortoisediff
git config --global difftool.tortoisediff.cmd "TortoiseGitMerge \$LOCAL \$REMOTE"

已经结束了

----供进一步阅读----

您可能还需要其他设置:

# you may want to disable prompt or merge backup
git config --global mergetool.keepBackup false
git config --global difftool.prompt false
git config --global mergetool.prompt false

# set the path only when it's not found in system path
git config --global mergetool.tortoisemerge.path "C:\Program Files\TortoiseGit\bin\TortoiseGitMerge.exe" 
git config --global difftool.tortoisdiff.path "C:\Program Files\TortoiseGit\bin\TortoiseGitMerge.exe"

要设置合并工具,你只需要设置正确的合并工具名称。它是官方支持的。
Git for windows installer包含了一个shell文件,用于运行tortoisegitmerge作为合并工具。它位于C:\Program Files\Git\mingw64\libexec\git-core\mergetools。(Git提供了4个变量用于合并:$BASE $LOCAL $REMOTE $MERGED,您可以在shell文件中检查它们。)
您可以使用以下命令检查计算机上支持的所有合并/比较工具:

git difftool --tool-help
git mergetool --tool-help

运行tortoisegitmerge,因为git diff工具不被git官方支持,可能是因为这个工具不支持目录比较(git difftool -d)。所以你需要配置difftool cmd来使用它作为git difftool。
tortoisegitmerge工具的手册位于:
https://tortoisegit.org/docs/tortoisegitmerge/tme-automation.html
你可以发现做diff文件最简单的方法是:
TortoiseGitMerge BaseFilePath MyFilePath [ TheirFilePath ] .
所以我对git difftool的命令使用这种方式。

evrscar2

evrscar24#

Klas Mellbourn的回答很棒!节省了我很多时间。一个缺点是,新的AddedRemoved文件在执行difftool命令时不会显示出来。没有什么可以比较的!下面是我在此基础上所做的:(灵感来自我同事的answer)。
1.在$Home目录下创建一个名为empty.empty的文件(在bash中执行start ~),如名字所示,保持它为空。
1.在$Home/bin目录中创建另一个名为tortoisediff.sh的文件,内容如下

#!/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"
这会使difftool引用tortoisediff.sh,而不是直接打开应用程序。
1.**请记住:**您必须先运行git add .,然后再运行git difftool --staged,而不是简单地运行git difftool

p8h8hvxi

p8h8hvxi5#

[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(便携式)

gv8xihay

gv8xihay6#

当rebasing时,我强烈建议切换$theirs$mine,因为合并和rebase-merge是不同的。
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"
ttygqcqt

ttygqcqt7#

对于在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"

相关问题