无法在Git中的两个单独分支中区分文件

时间:2021-07-20 10:40:27

I have FileA in branchA and FileB in branchB.

我在branchA中有FileA,在branchB中有FileB。

The problem is that I can access only one file at time. I would like to be able to compare the files by FileMerge or meld, since they are the only diffTools whichI have found for Mac.

问题是我一次只能访问一个文件。我希望能够通过FileMerge或meld来比较这些文件,因为它们是我为Mac找到的唯一的diffTools。

How can you diff by meld/FileMerge the two files?

你怎么能通过meld / FileMerge来区分两个文件?


[Solved]: 1st developed Problem: FileMerge does not allow standard input

[已解决]:第一个问题:FileMerge不允许标准输入

Masi: You can use opendiff to allow FileMerge to have files from standard input. So the next problem is to find how to make git's diff tool to use opendiff.

Masi:您可以使用opendiff来允许FileMerge从标准输入中获取文件。所以下一个问题是找到如何使用git的diff工具来使用opendiff。


2nd developed Problem: to make Git's diff tool to use opendiff in Mac

第二个开发的问题:使Git的diff工具在Mac中使用opendiff

4 个解决方案

#1


You can use "git mergetool" for merging, and in modern git (meaning version 1.6.3 and later) "git difftool" for comparing using graphical tools. Of course you would have to configure them first, but they do some autodetection (with some hardcoded preference, of course), and if I remember correctly opendiff support is built in.

您可以使用“git mergetool”进行合并,并使用现代git(意思是版本1.6.3及更高版本)“git difftool”进行比较,使用图形工具。当然你必须先配置它们,但是它们会做一些自动检测(当然还有一些硬编码的首选项),如果我记得正确的话,内置了opendiff支持。

And then of course you would be able to use your graphical tool (opendiff / FileMerge) as you would use ordinary "git diff", for example

当然,你可以像使用普通的“git diff”一样使用你的图形工具(opendiff / FileMerge),例如

prompt> git difftool somebranch:UNREADME otherbranch:README

#2


git supports branch names as part of the repository paths. Eg if you have the following files in your repository, README only on master, and UNREADME only on branch:

git支持分支名称作为存储库路径的一部分。例如,如果存储库中包含以下文件,则仅在master上使用README,在仅在分支上使用UNREADME:

master:README

branch:UNREADME

You can diff them via git with:

你可以通过git与它们区分:

git diff branch:UNREADME master:README

You can get a repository artifact to standard output with git show:

您可以使用git show获取标准输出的存储库工件:

git show branch1:UNREADME

So if your external diff utility can take 2 files on the bash prompt, you can diff them with something like:

因此,如果外部diff实用程序可以在bash提示符下获取2个文件,则可以使用以下内容对它们进行区分:

diff-command <(git show branch1:UNREADME) <(git show master:README)

Where the <(...) bash syntax takes the output of the enclosed command, runs it in a pipe and places the file path of the pipe on the command line.

在<(...)bash语法获取所附命令的输出的情况下,在管道中运行它并将管道的文件路径放在命令行上。

#3


If you're currently checkout out to branchA, for example, you can use the command:

例如,如果您当前已结帐到branchA,则可以使用以下命令:

git diff branchB path/to/common/file/between/branches.txt

You can then edit the diff if you want a subset of the changes, or leave it as is, and git apply the diff as a patch. As for a GUI tool that does this, hopefully someone else will have a suggestion there.

然后,如果您想要更改的子集,则可以编辑差异,或者保持原样,然后git将diff应用为补丁。至于这样做的GUI工具,希望其他人会在那里有一个建议。

#4


From the docs, you need something similar to the following in your .git/config file:

从文档中,您需要在.git / config文件中使用类似于以下内容的内容:

# Our diff algorithm
[diff]
    external = opendiff

#1


You can use "git mergetool" for merging, and in modern git (meaning version 1.6.3 and later) "git difftool" for comparing using graphical tools. Of course you would have to configure them first, but they do some autodetection (with some hardcoded preference, of course), and if I remember correctly opendiff support is built in.

您可以使用“git mergetool”进行合并,并使用现代git(意思是版本1.6.3及更高版本)“git difftool”进行比较,使用图形工具。当然你必须先配置它们,但是它们会做一些自动检测(当然还有一些硬编码的首选项),如果我记得正确的话,内置了opendiff支持。

And then of course you would be able to use your graphical tool (opendiff / FileMerge) as you would use ordinary "git diff", for example

当然,你可以像使用普通的“git diff”一样使用你的图形工具(opendiff / FileMerge),例如

prompt> git difftool somebranch:UNREADME otherbranch:README

#2


git supports branch names as part of the repository paths. Eg if you have the following files in your repository, README only on master, and UNREADME only on branch:

git支持分支名称作为存储库路径的一部分。例如,如果存储库中包含以下文件,则仅在master上使用README,在仅在分支上使用UNREADME:

master:README

branch:UNREADME

You can diff them via git with:

你可以通过git与它们区分:

git diff branch:UNREADME master:README

You can get a repository artifact to standard output with git show:

您可以使用git show获取标准输出的存储库工件:

git show branch1:UNREADME

So if your external diff utility can take 2 files on the bash prompt, you can diff them with something like:

因此,如果外部diff实用程序可以在bash提示符下获取2个文件,则可以使用以下内容对它们进行区分:

diff-command <(git show branch1:UNREADME) <(git show master:README)

Where the <(...) bash syntax takes the output of the enclosed command, runs it in a pipe and places the file path of the pipe on the command line.

在<(...)bash语法获取所附命令的输出的情况下,在管道中运行它并将管道的文件路径放在命令行上。

#3


If you're currently checkout out to branchA, for example, you can use the command:

例如,如果您当前已结帐到branchA,则可以使用以下命令:

git diff branchB path/to/common/file/between/branches.txt

You can then edit the diff if you want a subset of the changes, or leave it as is, and git apply the diff as a patch. As for a GUI tool that does this, hopefully someone else will have a suggestion there.

然后,如果您想要更改的子集,则可以编辑差异,或者保持原样,然后git将diff应用为补丁。至于这样做的GUI工具,希望其他人会在那里有一个建议。

#4


From the docs, you need something similar to the following in your .git/config file:

从文档中,您需要在.git / config文件中使用类似于以下内容的内容:

# Our diff algorithm
[diff]
    external = opendiff