Github Comparison View for 2 branches is incorrect?

Brad Parks picture Brad Parks · Sep 14, 2015 · Viewed 14.1k times · Source

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

Answer

VonC picture VonC · Sep 16, 2015

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.