git 如何比较github同一分支上的两个不同提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49837769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to compare two different commits on the same branch in github?
提问by ShanZhengYang
Comparing histories on the same branch is very confusing for me on GitHub. I struggle with this regularly:
在 GitHub 上比较同一分支上的历史记录对我来说非常混乱。我经常与这个斗争:
If I use compare/master
in the URL after the GitHub repo name, I can compare against other branches in the repo based on the options in the drop-down menus.
如果我compare/master
在 GitHub 存储库名称后的 URL 中使用,我可以根据下拉菜单中的选项与存储库中的其他分支进行比较。
https://help.github.com/en/articles/comparing-commits-across-time
https://help.github.com/en/articles/comparing-commits-across-time
However, I usually want to compare several commits on master.
但是,我通常想比较 master 上的几次提交。
How is this easily done? Could I get a more clear example?
这是如何轻松完成的?我能举个更清楚的例子吗?
回答by Pankaj Singhal
You can use the following URL structure to compare commits in the same branch:
您可以使用以下 URL 结构来比较同一分支中的提交:
github.com/<username>/<repo_name>/compare/<commit1>...<commit2>
Replace values for username
, repo_name
, commit1
& commit2
acc. to your project.
替换username
, repo_name
, commit1
& commit2
acc 的值。到您的项目。
The separator between the two commits is ...
i.e. (3 dots)
两次提交之间的分隔符是...
ie (3 点)
回答by Schwern
The article you linked has instructions for comparing commits.
您链接的文章包含比较提交的说明。
The GitHub comparison tool will accept any revision. Branches, tags, commit IDs, even dates. If you want to compare between two commits, give it the commit IDs. Here's their example.
GitHub 比较工具将接受任何修订。分支、标签、提交 ID,甚至日期。如果您想在两次提交之间进行比较,请为其提供提交 ID。这是他们的例子。
回答by wisbucky
You can use the Github Compare UI, which will generate the URL for you. Replace ORG
and REPO
with your values. The UI only lists branches, but you can also type in any valid Tags (e.g. v1.0.0
) or Commit IDs (e.g. 1a2b3c
).
您可以使用 Github 比较 UI,它会为您生成 URL。用你的价值观替换ORG
和REPO
。UI 仅列出分支,但您也可以输入任何有效的标签(例如v1.0.0
)或提交 ID(例如1a2b3c
)。
https://github.com/ORG/REPO/compare/
https://github.com/ORG/REPO/compare/
The URLs that get generated are in this format. You can also manually edit the URL with the REFs.
生成的 URL 就是这种格式。您还可以使用 REF 手动编辑 URL。
https://github.com/ORG/REPO/compare/REF1...REF2
https://github.com/ORG/REPO/compare/REF1...REF2
You can also use "2 dots" (direct diff) instead of "3 dots" (diff from last common commit). Same as git diff A..B
vs git diff A...B
.
您还可以使用“2 点”(直接差异)而不是“3 点”(与上次常见提交的差异)。与git diff A..B
vsgit diff A...B
相同。
https://github.com/ORG/REPO/compare/REF1..REF2
https://github.com/ORG/REPO/compare/REF1..REF2
If you want to compare across forks, then you need to add ORG2:
如果要跨分叉进行比较,则需要添加 ORG2:
https://github.com/ORG/REPO/compare/REF1...ORG2:REF2
https://github.com/ORG/REPO/compare/REF1...ORG2:REF2
There is documentation, but I didn't think it was that clear: https://help.github.com/en/github/committing-changes-to-your-project/comparing-commits-across-time
有文档,但我认为不是很清楚:https: //help.github.com/en/github/committing-changes-to-your-project/comparing-commits-across-time
回答by Kim Paulissen
to see the difference between branches or tags
查看分支或标签之间的区别
(branches if no pull request has been made)
(如果没有提出拉取请求,则分支)
- https://github.com/PyCQA/mccabe/compare/bug/39...master(diff between two branches
bug/39
andmaster
) - https://github.com/PyCQA/mccabe/compare/0.6.0...0.6.1(diff between two tags)
- https://github.com/PyCQA/mccabe/compare/0.6.1...master(diff between tag and master)
- https://github.com/PyCQA/mccabe/compare/bug/39...master(两个分支之间的差异
bug/39
和master
) - https://github.com/PyCQA/mccabe/compare/0.6.0...0.6.1(两个标签之间的差异)
- https://github.com/PyCQA/mccabe/compare/0.6.1...master(标签和主人之间的差异)
Notes:
笔记:
(if a pull request has been made you can see the changes inside the PR, no longer via the compare url)
You can use the dropdowns to select different branches or tags:
take care of the order, eg. https://github.com/PyCQA/mccabe/compare/master...0.6.1will give no results
you can choose between 2-dot (..) or 3-dot (...) notation
(如果已发出拉取请求,您可以在 PR 中看到更改,而不再通过比较 URL)
照顾订单,例如。https://github.com/PyCQA/mccabe/compare/master...0.6.1不会给出任何结果
您可以选择 2 点 (..) 或 3 点 (...) 表示法