Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub compare view for current versions of branches

Tags:

git

branch

github

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.

like image 382
Avril Avatar asked Jul 01 '14 19:07

Avril


People also ask

How do I compare two GitHub branches?

Comparing branches is as easy as selecting the “compare to branch” option while perusing the feature branch you'd like to compare to another. The compare to branch option in GitHub Desktop is located under the “Branch” in the main menu at the top of the interface.

How do I see differences in GitHub?

On the Github, go to the Source view of your project. You will see a link named 'Branch List'. Once the page opens you can see a list of all the remote branches. Hit on the Compare button in front of any of the available branches to see the difference between two branches.

How do I compare git versions?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.


2 Answers

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.

like image 75
nulltoken Avatar answered Oct 02 '22 10:10

nulltoken


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.

like image 33
VonC Avatar answered Oct 02 '22 08:10

VonC