GitHub compare view for current versions of branches

懵懂的女人 提交于 2019-12-03 08:55:52

问题


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.


回答1:


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.




回答2:


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:

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.



来源:https://stackoverflow.com/questions/24517820/github-compare-view-for-current-versions-of-branches

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!