16

Is there a way to use GitHub's "compare view" to view the diff between the current versions of two branches? (That is, to view the same diff that you would get if you did git diff <a-branch> <another-branch>.)

I have made a small example here. There are two branches: "master" and "other-branch". If I do git diff master..other-branch, this is the diff:

diff --git a/README.md b/README.md
index 495cc9f..3d2c3a0 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
 Hello there!
+
+This is a commit to the "other-branch" branch.

You can see from that diff that the difference between the "master" branch and the "other-branch" branch is the addition of one blank line and one line of text, and there are no deletions.

However, if I try to use GitHub compare view (https://github.com/akenney/compare-view-test/compare/other-branch or https://github.com/akenney/compare-view-test/compare/master...other-branch), it shows this diff:

-This is a commit to the master branch.
+Hello there!
+
+This is a commit to the "other-branch" branch.

It is comparing the "other-branch" branch with an old version of the "master" branch, not with the current version. The same thing happens even if I specify the particular commits to compare (https://github.com/akenney/compare-view-test/compare/8ed0d53...e4470ec) - the diff that it's showing is not the diff between those two commits.

Avril
  • 813
  • 1
  • 9
  • 20
  • You now (Sept. 2018) can use GitHub's "compare view" to view the diff between the current versions of two branches. See [my answer below](https://stackoverflow.com/a/52487331/6309). – VonC Sep 24 '18 at 21:02

2 Answers2

11

GitHub only supports the triple dots (...) range shortcut specification.

From the git diff documentation:

git diff [--options] .. [--] […]

This is synonymous to the previous form. If on one side is omitted, it will have the same effect as using HEAD instead.

git diff [--options] ... [--] […]

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.

nulltoken
  • 64,429
  • 20
  • 138
  • 130
  • 3
    Okay ... so the answer to the question is no. Oh well. Thanks. I didn't know that that's what the three-dots meant, and I'm not sure why GitHub would not support the normal two-dots type of diff. – Avril Jul 01 '14 at 20:35
  • @Avril , I did not understand this answer. Is it possible to make github comparing the latest versions of two branches? and how to do it? –  Jul 04 '18 at 09:40
  • This answer is talking about `git` rather than `GitHub`, which is what the op was asking. – testworks Aug 07 '20 at 05:38
3

GitHub now (Sept. 2018, 4 years later) explicitly supports "Three-dot and two-dot Git diff comparisons".

The URL https://github.com/github/linguist/compare/c3a414e..faf7c6 will display:

direct two-dots diff

The message is:

This is a direct comparison between two commits made in this repository or its related forks

Now you can easily see the differences between two commits without comparing from their common merge base commit like a three dot comparison would.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250