如何使用GitHub的在线比较视图显示“仅文件内容"与“仅文件内容"之间的区别?两个分支? [英] How can I use GitHub's online compare view to show the difference of "just the file contents" of two branches?
问题描述
我想比较GitHub存储库的两个分支的仅文件内容".例如,当我对拉取请求使用默认的比较视图时,即使文件相同,它仍会显示一些差异.
I want to compare "just the file contents" of two branches of a GitHub repository. When I use the default compare view for a pull request for example, it does still show me some diffs, even though the files are identical.
您可以重现这种情况:
- 使用文件
README
在GitHub上创建新的存储库. - 将文本添加到
README
,并将提交推送到新的分支duplicate
. - 将相同的文本添加到
master
分支的README
中. 来自两个分支的 - 两个
README
文件现在具有相同的内容,但https://github.com/user/repo/compare/duplicate 显示了duplicate
和master
之间的区别.
- Create new repository on GitHub with a file
README
. - Add text to
README
and push the commit to a new branchduplicate
. - Add the same text to
README
of themaster
branch. - Both
README
files from both branches now have identical content, yet https://github.com/user/repo/compare/duplicate shows a diff betweenduplicate
andmaster
.
我知道显示此差异是因为对两个文件所做的更改是由不同的提交引入的,但是有时仅查看不同的文件内容(即i)更有用.e.合并将真正改变什么.在上面的示例中, master
完全不会更改.
I know this diff is being shown because the changes to both files have been introduced by different commits, but sometimes it's more useful to only see the differing file contents, i. e. what would really get changed by merging. In the example above, master
wouldn't change at all.
据我了解, git
CLI命令通过其-no-index
选项为本地文件夹提供了此功能.因此,我可以将这两个分支克隆到本地文件系统中,并与 git diff --no-index
进行比较.我如何才能做到这一点而不必先克隆它们?我想在GitHub上在线查看差异.
As far as I understand, the git
CLI command provides this feature for local folders with its --no-index
option. So, I could clone the two branches to my local file system and compare them with git diff --no-index
. How can I achieve this without having to clone them first? I want to view the difference online on GitHub.
更新:我认为该问题与-no-index
选项无关.如果我下载存储库并在本地使用 git diff
,则会注意到以下内容: git diff master..duplicate
(两个点)不会显示差异,并且git diff master ... duplicate
(三个点)将显示与GitHub的在线比较相同.
Update: I don't think the issue has anything to do with the --no-index
option. If I download the repository and use git diff
locally, I noticed the following: git diff master..duplicate
(two dots) won't show a difference and git diff master...duplicate
(three dots) will show the same as GitHub's compare online.
因此,此问题类似于以下问题: Github比较视图2个分支不正确?
Therefore, this question is similar to this one: Github Comparison View for 2 branches is incorrect?
简而言之:目前,GitHub的比较视图始终使用带有三个点的 git diff
.有关两个点和三个点之间差异的更多信息,请参见 https://git-scm.com/docs/git-diff
In short: Currently, GitHub's compare view always uses git diff
with three dots. More information about the difference between two and three dots also at https://git-scm.com/docs/git-diff
推荐答案
现在(2018年9月)受支持.
参见"做点,两个点提交比较"
This is now (Sept. 2018) supported.
See "Dos dots, the two dot commit comparison"
这创建了在两次提交之间进行直接两点"比较的功能.
现在,您可以轻松地看到两个提交之间的差异,而无需像三点比较那样将它们与常见的合并基础提交进行比较.
请参阅"例如:
See "Three-dot and two-dot Git diff comparisons".
For example:
https://github.com/github/linguist/compare/c3a414e..faf7c6
这篇关于如何使用GitHub的在线比较视图显示“仅文件内容"与“仅文件内容"之间的区别?两个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!