git 2 个分支的 Github 比较视图不正确?

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

Github Comparison View for 2 branches is incorrect?

gitgithubgit-diff

提问by Brad Parks

When I do a Github comparison viewbetween masterand another branch A, Github seems to be comparing the HEAD version of Awith an older, non head version of master.

当我做了Github上比较视图之间master和另一个分支A,Github上似乎比较的HEAD版本A与老版本的非球头型的master

I looked into it, and from what I can tell it sounds like Github is comparing branch Aagainst a common ancestor of master. It's not actually comparing it to what's currently at the HEADof master.

我调查了一下,据我所知,Github 正在将分支Amaster. 它实际上并没有将它与当前在HEADmaster 上的内容进行比较。

Is there a way to diff the HEAD of master against the HEAD of Branch Ain Github?

有没有办法A在 Github中将 master 的 HEAD 与 Branch 的 HEAD 进行比较?

If not, why not? This seems like a feature every developer would want to be able to do. Or is there some process that should be done that I'm perhaps missing? I'd like to be able to create a Pull Request directly from one of these diffs.

如果没有,为什么不呢?这似乎是每个开发人员都希望能够实现的功能。或者是否应该完成一些我可能遗漏的过程?我希望能够直接从这些差异之一创建拉取请求。

EDIT:Here's an example repo that shows the problem

编辑:这是一个显示问题的示例存储库

https://github.com/bradparks/test_github_diff_view

https://github.com/bradparks/test_github_diff_view

  • I created a new repo that contains a single file, README.md
  • I set this file to contain a single line v100.
  • I then branched master into a new branch A, and changed the line to `v200'
  • I then changed the value in the master branch to 'v300', and then compared the 2 branches using the compare link

    https://github.com/bradparks/test_github_diff_view/compare/A

    and I see the following unexpected result. Why isn't it diffing against v300instead of v100?

    enter image description here

  • 我创建了一个包含单个文件 README.md 的新存储库
  • 我将此文件设置为包含一行v100
  • 然后我将 master 分支到一个新分支A,并将该行更改为“v200”
  • 然后我将 master 分支中的值更改为“v300”,然后使用比较链接比较了 2 个分支

    https://github.com/bradparks/test_github_diff_view/compare/A

    我看到了以下意想不到的结果。为什么它不与v300而不是不同v100

    在此处输入图片说明

采纳答案by VonC

Is there a way to diff the HEAD of master against the HEAD of Branch A in Github?

有没有办法在 Github 中将 master 的 HEAD 与 Branch A 的 HEAD 进行比较?

Sept 2018: yes: GitHub now explicitly supports "Three-dot and two-dot Git diff comparisons". See an example here.
keisukementions in the commentsa similar initiative on Bitbucket.

2018 年 9 月:是:GitHub 现在明确支持“三点和两点 Git 差异比较”。请参阅此处的示例
keisuke在评论中提到一个关于 Bitbucket类似倡议

Original answer 2015:

2015 年的原始答案:

No: as mentioned in "GitHub compare view for current versions of branches", GitHub only supports the triple dots (...) range shortcut specification.
That is:

否:如“当前版本分支的 GitHub 比较视图”中所述,GitHub 仅支持三点 (...) 范围快捷方式规范。
那是:

This form is to view the changes on the branch containing and up to the second , starting at a common ancestor of both.

"git diff A...B" is equivalent to "git diff $(git-merge-base A B) B".
You can omit any one of , which has the same effect as using HEAD instead.

此表单用于查看包含 和 直到第二个 的分支上的更改,从两者的共同祖先开始。

git diff A...B”相当于“ git diff $(git-merge-base A B) B”。
您可以省略任何一个,这与使用 HEAD 具有相同的效果。

The official GitHub helpmentions this feature as:

官员GitHub的帮助提到这个功能为:

The most common use of Compare is to compare branches, such as when you're starting a new Pull Request.

Compare 最常见的用途是比较分支,例如当您开始一个新的 Pull Request 时。

In that scenario, the PR branch starts from master (or should be rebased on top of master anyway), which means master HEAD is the base between master and the PR branch.

在这种情况下,PR 分支从 master 开始(或者无论如何应该重新基于 master),这意味着 master HEAD 是 master 和 PR 分支之间的基础。

But when the two branches have forked, the comparison is no longer between HEADs, but between one common ancestor and one HEAD: git diff $(git-merge-base master B) B.

但是当两个分支分叉后,比较的不再是在 之间HEADs,而是在一个共同的祖先和一个 HEAD: 之间git diff $(git-merge-base master B) B

Note: even if you were to specify two SHA1 directly, as it is clearly documented in "Comparing commits", that would stilldo a git diff $(git-merge-base A B) B.
That would notdo a diff directly between the two commits.

注意:即使您要直接指定两个 SHA1,正如“比较提交”中明确记录的那样,仍然会执行git diff $(git-merge-base A B) B.
这将不会直接做两次提交之间的差异。

回答by leoger

Is there a way to diff the HEAD of master against the HEAD of Branch A in Github?

有没有办法在 Github 中将 master 的 HEAD 与 Branch A 的 HEAD 进行比较?

[EDIT: Nope, I was wrong. I managed had a URL which looked like it would be doing the right thing and the diff on the page looked right, but that was an accident. If you really want to know more, check the history of this answer.]

[编辑:不,我错了。我管理了一个 URL,它看起来像是在做正确的事情,页面上的差异看起来是正确的,但这是一个意外。如果您真的想了解更多信息,请查看此答案的历史记录。]

回答by MikeBeaton

Just another thought. If you want to create a pull request from the diff between your work and the head of the master branch (as per o.p.), then what you need to do is to firstly rebase your own branch off the master branch git rebase <master>and then make the pull request.

只是另一个想法。如果您想从您的工作和 master 分支的负责人之间的差异创建拉取请求(根据操作),那么您需要做的是首先将您自己的分支从 master 分支重新设置为基础git rebase <master>,然后发出拉取请求.

But you typically don't need to do this, Git is very clever with merges and will normally be able to add your work in to the master branch as you want it added, even if you don't rebase first.

但是您通常不需要这样做,Git 在合并方面非常聪明,并且通常能够将您的工作添加到您想要添加的主分支中,即使您没有先变基。