Git Diff 与 Beyond Compare

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2069490/
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-10 07:39:54  来源:igfitidea点击:

Git Diff with Beyond Compare

gitbeyondcompare

提问by Avanst

I have succeeded in getting git to start Beyond Compare 3 as a diff tool however, when I do a diff, the file I am comparing against is not being loaded. Only the latest version of the file is loaded and nothing else, so there is nothing in the right pane of Beyond Compare.

我已经成功地让 git 启动 Beyond Compare 3 作为差异工具,但是,当我进行差异时,我正在比较的文件没有被加载。仅加载最新版本的文件,没有其他内容,因此 Beyond Compare 的右侧窗格中没有任何内容。

I am running git 1.6.3.1 with Cygwin with Beyond Compare 3. I have set up beyond compare as they suggest in the support part of their website with a script like such:

我正在使用带有 Beyond Compare 3 的 Cygwin 运行 git 1.6.3.1。我已经按照他们网站的支持部分中的建议进行了设置,使用如下脚本:

#!/bin/sh  
# diff is called by git with 7 parameters:  
# path old-file old-hex old-mode new-file new-hex new-mode  
"path_to_bc3_executable" "" "" | cat

Has anyone else encountered this problem and know a solution to this?

有没有其他人遇到过这个问题并知道解决方案?

Edit:
I have followed the suggestions by VonC but I am still having exactly the same problem as before. I am kinda new to Git so perhaps I am not using the diff correctly.

编辑:
我遵循了 VonC 的建议,但我仍然遇到与以前完全相同的问题。我对 Git 有点陌生,所以也许我没有正确使用差异。

For example, I am trying to see the diff on a file with a command like such:
git diff main.css

例如,我试图用这样的命令查看文件上的
差异:git diff main.css

Beyond Compare will then open and only display my current main.css in the left pane, there is nothing in the right pane. I would like the see my current main.css in the left pane compared to the HEAD, basically what I have last committed.

Beyond Compare 将打开,只在左窗格中显示我当前的 main.css,右窗格中没有任何内容。与 HEAD 相比,我希望在左侧窗格中看到我当前的 main.css,基本上是我上次提交的内容。

My git-diff-wrapper.sh looks like this:

我的 git-diff-wrapper.sh 看起来像这样:

#!/bin/sh  
# diff is called by git with 7 parameters:  
# path old-file old-hex old-mode new-file new-hex new-mode  
"c:/Program Files/Beyond Compare 3/BCompare.exe" "" "" | cat

My git config looks like this for Diff:

对于 Diff,我的 git 配置如下所示:

[diff]  
external = c:/cygwin/bin/git-diff-wrapper.sh

回答by yehnan

I don't use extra wrapper .sh files. My environment is Windows XP, git 1.7.1 on cygwin, and Beyond Compare 3. Following is my .git/configfile.

我不使用额外的包装 .sh 文件。我的环境是 Windows XP,cygwin 上的 git 1.7.1 和 Beyond Compare 3。以下是我的.git/config文件。

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    #use cygpath to transform cygwin path $LOCAL (something like /tmp/U5VvP1_abc) to windows path, because bc3 is a windows software
    cmd = \"c:/program files/beyond compare 3/bcomp.exe\" "$(cygpath -w $LOCAL)" "$REMOTE"
[merge]
    tool = bc3
[mergetool]
    prompt = false
[mergetool "bc3"]
    #trustExitCode = true
    cmd = \"c:/program files/beyond compare 3/bcomp.exe\" "$LOCAL" "$REMOTE" "$BASE" "$MERGED"

Then, I use $ git difftoolto compare and $ git mergetoolto merge.

然后,我使用$ git difftool进行比较并使用$ git mergetool进行合并。

About trustExitCode: For a custom merge command, specify whether the exit code of the merge command can be used to determine whether the merge was successful. If this is not set to true then the merge target file timestamp is checked and the merge assumed to have been successful if the file has been updated, otherwise the user is prompted to indicate the success of the merge.

关于trustExitCode:对于自定义合并命令,指定是否可以通过合并命令的退出码来判断合并是否成功。如果未设置为 true,则检查合并目标文件时间戳,如果文件已更新,则假定合并已成功,否则将提示用户指示合并成功。

回答by Nick Josevski

Thanks to @dahlbyk, the author of Posh-Git, for posting his config as a gist. It helped me resolve my configuration issue.

感谢Posh-Git的作者@dahlbyk将他的配置作为 gist 发布。它帮助我解决了配置问题。

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    cmd = \"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\"
[merge]
    tool = bc3
[mergetool]
    prompt = false
    keepBackup = false
[mergetool "bc3"]
    cmd = \"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
    trustExitCode = true
[alias]
    dt = difftool
    mt = mergetool

回答by user

Run these commands for Beyond Compare 2:

为 Beyond Compare 2 运行以下命令:

git config --global diff.tool bc2
git config --global difftool.bc2.cmd "\"c:/program files (x86)/beyond compare 2/bc2.exe\" \"$LOCAL\" \"$REMOTE\""
git config --global difftool.prompt false

Run these commands for Beyond Compare 3:

为 Beyond Compare 3 运行以下命令:

git config --global diff.tool bc3
git config --global difftool.bc3.cmd "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
git config --global difftool.prompt false

Then use git difftool

然后使用 git difftool

回答by Daniel Magnusson

Official documentationworked for me

官方文档对我有用

回答by nachonachoman

Here is my config file. It took some wrestling but now it is working. I am using windows server, msysgit and beyond compare 3 (apparently an x86 version). Youll notice that I dont need to specify any arguments, and I use "path" instead of "cmd".

这是我的配置文件。花了一些时间,但现在它正在起作用。我正在使用 Windows 服务器、msysgit 和其他比较 3(显然是 x86 版本)。你会注意到我不需要指定任何参数,我使用“path”而不是“cmd”。

[user]
        name = PeteW
        email = [email protected]
[diff]
        tool = bc3
[difftool]
        prompt = false
[difftool "bc3"]
        path = /c/Program Files (x86)/Beyond Compare 3/BComp.exe
[merge]
        tool = bc3
[mergetool]
        prompt = false
        keepBackup = false
[mergetool "bc3"]
        path = /c/Program Files (x86)/Beyond Compare 3/BComp.exe
        trustExitCode = true
[alias]
        dt = difftool
        mt = mergetool

回答by Mark Conway

it looks like BC3 only supports 3 way merge for PRO Edition. http://www.scootersoftware.com/moreinfo.php?zz=kb_editions

看起来 BC3 只支持 PRO 版的 3 路合并。 http://www.scootersoftware.com/moreinfo.php?zz=kb_editions

回答by VonC

The Beyond Compare support pageis a bit brief.

除了比较支持页面是有点短。

Check my diff.external answerfor more (regarding the exact syntax)

检查我的diff.external 答案以获取更多信息(关于确切的语法)

Extract:

提炼:

$ git config --global diff.external <path_to_wrapper_script>

at the command prompt, replacing with the path to "git-diff-wrapper.sh", so your ~/.gitconfigcontains

在命令提示符下,替换为“ git-diff-wrapper.sh”的路径,因此您的~/.gitconfig包含

-->8-(snip)--
[diff]
    external = <path_to_wrapper_script>
--8<-(snap)--

Be sure to use the correct syntax to specify the paths to the wrapper script and diff tool, i.e. use forward slashed instead of backslashes. In my case, I have

确保使用正确的语法来指定包装脚本和差异工具的路径,即使用正斜杠而不是反斜杠。就我而言,我有

[diff]
    external = c:/Documents and Settings/sschuber/git-diff-wrapper.sh

in .gitconfigand

.gitconfig

"d:/Program Files/Beyond Compare 3/BCompare.exe" "" "" | cat

in the wrapper script.

在包装脚本中。



Note: you can also use git difftool.

注意:您也可以使用git difftool.

回答by z33

Please notice you make a wrong path of $2. because you are under Cygwin but BC3 not, so you should specify a full path for it. such as "d:/cygwin$2"

请注意,您走错了 2 美元的路径。因为您在 Cygwin 下,但不在 BC3 下,所以您应该为其指定完整路径。例如“d:/cygwin$2”

Please refer my git-diff-wrapper.sh here:

请在此处参考我的 git-diff-wrapper.sh:

$ cat ~/git-diff-wrapper.sh
#!/bin/sh
echo 
echo 
/cygdrive/c/Program\ Files\ \(x86\)/Beyond\ Compare\ 3/BCompare.exe "d:/programs/cygwin" ""

Good luck.

祝你好运。

回答by mitaka

Update for BC4 64bit: This works for Git for Windows v.2.16.2 and Beyond Compare 4 - v.4.2.4 (64bit Edition)

BC4 64 位更新:这适用于 Git for Windows v.2.16.2 和 Beyond Compare 4 - v.4.2.4(64 位版)

I manually edited the .gitconfig file located in my user root "C:\Users\MyUserName" and replaced the diff/difftool and merge/mergetool tags with

我手动编辑了位于我的用户根目录“C:\Users\MyUserName”中的 .gitconfig 文件,并将 diff/difftool 和 merge/mergetool 标签替换为

[diff]
  tool = bc
[difftool "bc"]
  path = 'C:/Program Files/Beyond Compare 4/BComp.exe'
[difftool "bc"]
  cmd = \"C:/Program Files/Beyond Compare 4/BComp.exe\" \"$LOCAL\" \"$REMOTE\"
[difftool]
  prompt = false
[merge]
  tool = bc
[mergetool "bc"]
  path = 'C:/Program Files/Beyond Compare 4/BComp.exe'
[mergetool "bc"]
  cmd = \"C:/Program Files/Beyond Compare 4/BComp.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"

回答by sarabdeep singh

If you are running windows 7 (professional) and Git for Windows (v 2.15 or above), you can simply run below command to find out what are different diff tools supported by your Git for Windows

如果您正在运行 Windows 7(专业版)和 Git for Windows(v 2.15 或更高版本),您只需运行以下命令即可找出您的 Git for Windows 支持哪些不同的差异工具

git difftool --tool-help

You will see output similar to this

您将看到与此类似的输出

git difftool --tool=' may be set to one of the following:
vimdiff vimdiff2 vimdiff3

git difftool --tool=' 可以设置为以下之一:
vimdiff vimdiff2 vimdiff3

it means that your git does not support(can not find) beyond compare as difftool right now.

这意味着您的 git 现在不支持(找不到)无法与 difftool 进行比较。

In order for Git to find beyond compare as valid difftool, you should have Beyond Compare installation directoryin your system pathenvironment variable. You can check this by running bcompare from shell(cmd, git bash or powershell. I am using Git Bash). If Beyond Compare does not launch, add its installation directory (in my case, C:\Program Files\Beyond Compare 4) to your system path variable. After this, restart your shell. Git will show Beyond Compare as possible difftool option. You can use any of below commands to launch beyond compare as difftool (for example, to compare any local file with some other branch)

为了让 Git 找到Beyondcompare 作为有效的 difftool,你应该在你的系统路径环境变量中有Beyond Compare 安装目录。您可以通过从 shell(cmd、git bash 或 powershell)运行 bcompare 来检查这一点。我正在使用 Git Bash。如果 Beyond Compare 没有启动,请将其安装目录(在我的例子中,C:\Program Files\Beyond Compare 4)添加到您的系统路径变量中。在此之后,重新启动您的外壳。Git 将显示 Beyond Compare 作为可能的 difftool 选项。您可以使用以下任何命令来作为 difftool 启动而不是比较(例如,将任何本地文件与某个其他分支进行比较)

git difftool -t bc branchnametocomparewith -- path-to-file
or 
git difftool --tool=bc branchnametocomparewith -- path-to-file

You can configure beyond compare as default difftool using below commands

您可以使用以下命令将 Beyond compare 配置为默认 difftool

   git config --global diff.tool bc

p.s. keep in mind that bc in above command can be bc3 or bc based upon what Git was able to find from your path system variable.

ps 请记住,根据 Git 能够从您的路径系统变量中找到的内容,上述命令中的 bc 可以是 bc3 或 bc。