使用 BeyondCompare 查看 GIT 中文件之间的差异

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

Use BeyondCompare to see difference between files in GIT

gitgit-diffbeyondcomparebeyondcompare3

提问by SharpCoder

Before I commit my changes, I want to see the difference using BeyondCompare in GIT. How can I configure BeyondCompare to see difference in my files.

在提交更改之前,我想看看在 GIT 中使用 BeyondCompare 的区别。如何配置 BeyondCompare 以查看文件中的差异。

I looked at this linkbut it did not help.

我查看了此链接,但没有帮助。

BeyondCompare is installed at this location in my system: C:\program files\Beyond Compare\BCompare.exe

BeyondCompare 安装在我系统的这个位置: C:\program files\Beyond Compare\BCompare.exe

I ran following two commands:

我运行了以下两个命令:

 git config --global merge.tool bc

git config --global mergetool.bc.path "C:\program files\Beyond Compare\BCompare.exe"

I am using GIT on Windows 7.

我在 Windows 7 上使用 GIT。

Thanks !!

谢谢 !!

回答by SharpCoder

This linktells the way to set up BeyondComapre as the diff tool in git

链接介绍了在 git 中将 BeyondComapre 设置为差异工具的方法

git config --global diff.tool bc3
git config --global difftool.bc3.path "c:/program files/beyond compare 3/bcomp.exe"

To launch a diff using Beyond Compare, use the command "git difftool foofile.txt".

要使用 Beyond Compare 启动差异,请使用命令“ git difftool foofile.txt”。

回答by RBT

I'll just elaborate more on @SharpCoder's accepted answer.

我将详细说明@SharpCoder 接受的答案。

The first command that we run is as below:

我们运行的第一个命令如下:

git config --global diff.tool bc3

The above command creates below entry in .gitconfigfound in %userprofile%directory:

上面的命令在.gitconfigfound in %userprofile%directory 中创建以下条目:

[diff]
    tool = bc3

Then you run below command (Running this command is redundant in this particular case and is required in some specialized cases only. You will know it in a short while):

然后你运行下面的命令(在这种特殊情况下运行这个命令是多余的,只有在某些特殊情况下才需要。你很快就会知道它):

git config --global difftool.bc3.path "c:/program files/beyond compare 3/bcomp.exe"

Above command creates below entry in .gitconfigfile:

上面的命令在.gitconfig文件中创建以下条目:

[difftool "bc3"]
    path = c:/program files/Beyond Compare 3/bcomp.exe

The thing to know here is the key bc3. This is a well known key to git corresponding to a particular version of well known comparison tools available in market (bc3corresponds to 3rd version of Beyond Compare tool). If you want to see all pre-defined keys just run git difftool --tool-helpcommand on git bash. It returns below list:

这里要知道的事情是关键bc3。这是一个众所周知的 git 密钥,对应于市场上可用的知名比较工具的特定版本(bc3对应于 Beyond Compare 工具的第 3 版)。如果您想查看所有预定义的键,只需git difftool --tool-help在 git bash 上运行命令。它返回以下列表:

vimdiff
vimdiff2
vimdiff3
araxis
bc
bc3
codecompare
deltawalker
diffmerge
diffuse
ecmerge
emerge
examdiff
gvimdiff
gvimdiff2
gvimdiff3
kdiff3
kompare
meld
opendiff
p4merge
tkdiff
winmerge
xxdiff

You can use any of the above keys or define a custom key of your own. If you want to setup a new tool altogether(or a newly released version of well-known tool) which doesn't map to any of the keys listed above then you are free to map it to any of keys listed above or to a newcustom key of your own.

您可以使用上述任何键或定义您自己的自定义键。如果您想设置一个新工具(或新发布的知名工具的新版本),但它没有映射到上面列出的任何键,那么您可以自由地将它映射到上面列出的任何键或一个新的您自己的自定义密钥。

What if you have to setup a comparison tool which is

如果您必须设置一个比较工具怎么办

  • Absolutely new in market
  • 绝对新鲜的市场

OR

或者

  • A new version of an existing well known tool has got released which is not mapped to any pre-defined keys in git?
  • 现有知名工具的新版本已发布,但未映射到 git 中的任何预定义键

Like in my case, I had installed beyond compare 4. beyond compare is a well-known tool to git but its version 4 release is not mapped to any of the existing keys by default. So you can follow any of the below approaches:

就像在我的情况下,我安装了 Beyond compare 4。 Beyond compare 是一个众所周知的 git 工具,但它的第 4 版默认没有映射到任何现有的键。因此,您可以遵循以下任何一种方法:

  1. I can map beyond compare 4 tool to already existing key bc3which corresponds to beyond compare 3 version. I didn't have beyond compare version 3 on my computer so I didn't care. If I wanted I could have mapped it to any of the pre-defined keys in the above list also e.g. examdiff.

    If you map well known version of tools to appropriate already existing/well- known key then you would not need to run the second command as their install path is already known to git.

    For e.g. if I had installed beyond compare version 3 on my box then having below configuration in my .gitconfigfile would have been sufficient to get going:

    [diff]
    tool = bc3
    

    But if you want to change the default associated tool then you end up mentioning the pathattribute separately so that git gets to know the path from where you new tool's exe has to be launched. Here is the entry which foxes git to launch beyond compare 4 instead. Note the exe's path:

    [difftool "bc3"]
    path = c:/program files/Beyond Compare 4/bcomp.exe
    
  2. Most cleanest approachis to define a new key altogether for the new comparison tool or a new version of an well known tool. Like in my case I defined a new key bc4so that it is easy to remember. In such a case you have to run two commands in all but your second command will not be setting path of your new tool's executable. Instead you have to set cmdattribute for your new tool as shown below:

    git config --global diff.tool bc4
    
    git config --global difftool.bc4.cmd "\"C:\Program Files\Beyond Compare 4\bcomp.exe\" -s \"$LOCAL\" -d \"$REMOTE\""
    

    Running above commands creates below entries in your .gitconfigfile:

    [diff]
    tool = bc4
    [difftool "bc4"]
    cmd = \"C:\Program Files\Beyond Compare 4\bcomp.exe\" -s \"$LOCAL\" -d \"$REMOTE\"
    
  1. 我可以将 Beyond compare 4 工具映射到bc3与 Beyond compare 3 版本相对应的现有密钥。我没有在我的电脑上比较版本 3,所以我不在乎。如果我愿意,我可以将它映射到上面列表中的任何预定义键,例如examdiff.

    如果您将众所周知的工具版本映射到适当的现有/众所周知的密钥,那么您将不需要运行第二个命令,因为 git 已经知道它们的安装路径

    例如,如果我在我的盒子上安装了超出比较版本 3 的版本,那么在我的.gitconfig文件中具有以下配置就足够了:

    [diff]
    tool = bc3
    

    但是,如果您想更改默认的关联工具,那么您最终会path单独提及该属性,以便 git 了解必须启动新工具的 exe 的路径。这是使 git 启动而不是比较 4 的条目。注意exe的路径:

    [difftool "bc3"]
    path = c:/program files/Beyond Compare 4/bcomp.exe
    
  2. 最简洁的方法是为新的比较工具或知名工具的新版本定义一个新的密钥。就像我的情况一样,我定义了一个新密钥,bc4以便于记住。在这种情况下,您必须同时运行两个命令,但第二个命令不会设置新工具可执行文件的路径。相反,您必须cmd为新工具设置属性,如下所示:

    git config --global diff.tool bc4
    
    git config --global difftool.bc4.cmd "\"C:\Program Files\Beyond Compare 4\bcomp.exe\" -s \"$LOCAL\" -d \"$REMOTE\""
    

    运行以上命令会在您的.gitconfig文件中创建以下条目:

    [diff]
    tool = bc4
    [difftool "bc4"]
    cmd = \"C:\Program Files\Beyond Compare 4\bcomp.exe\" -s \"$LOCAL\" -d \"$REMOTE\"
    

I would strongly recommend you to follow approach # 2 to avoid any confusion for yourself in future.

我强烈建议您遵循方法#2,以避免将来对自己造成任何混淆。

回答by user1941126

Beyond compare is a mergetool and a diff tool. I have it for both operations anyway. When I want to see the differences between my current state and the last commited I write

Beyond compare 是一个合并工具和一个差异工具。无论如何,我对这两个操作都有它。当我想查看当前状态和上次提交的状态之间的差异时,我会写

    git diff 

for a fast text output and small changes and

用于快速的文本输出和小的更改以及

   git difftool

for changes in multiple files. Also keep in mind that you can do a git log, copy the first part of your commit's hash value and do a

用于更改多个文件。还要记住,您可以执行 git log,复制提交哈希值的第一部分并执行

   git difftool (commit1) (commit2)

and compare all the files one after another (very productive and useful)

并一个接一个地比较所有文件(非常高效和有用)

回答by Simson

The instruction refered in the question worked last time I tried it, but I think you should run the commands in git bash and replace backslash in your path with forward slash.

问题中提到的指令在我上次尝试时有效,但我认为您应该在 git bash 中运行命令并将路径中的反斜杠替换为正斜杠。

git config --global merge.tool bc
git config --global mergetool.bc.path "C:/program files/Beyond Compare/BCompare.exe"