Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Comparison View for 2 branches is incorrect?

When I do a Github comparison view between master and another branch A, Github seems to be comparing the HEAD version of A with an older, non head version of master.

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

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

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

  • 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 v300 instead of v100?

    enter image description here

like image 310
Brad Parks Avatar asked Sep 14 '15 17:09

Brad Parks


3 Answers

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

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

Original answer 2015:

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

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.

The official GitHub help mentions this feature as:

The most common use of Compare is to compare branches, such as when you're starting a new 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.

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.

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

like image 81
VonC Avatar answered Oct 13 '22 00:10

VonC


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

[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.]

like image 42
leoger Avatar answered Oct 13 '22 00:10

leoger


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.

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.

like image 45
MikeBeaton Avatar answered Oct 12 '22 23:10

MikeBeaton