如何比较github中同一分支上的两个不同的提交?

Sha*_*ang 27 git github

在GitHub上比较同一分支的历史对我来说非常困惑.我经常挣扎:

如果我compare/master在github repo名称之后使用URL,我可以根据下拉菜单中的选项与repo中的其他分支进行比较

https://help.github.com/articles/comparing-commits-across-time/

但是,我通常想比较master上的几个提交.

这怎么容易做到?我能得到一个更明确的例子吗?

Pan*_*hal 53

您可以使用以下URL结构来比较同一分支中的提交:

github.com/<username>/<repo_name>/compare/<commit1>...<commit2>
Run Code Online (Sandbox Code Playgroud)

替换为值username,repo_name,commit1commit2累计.到你的项目

  • 这个工作正常我想知道为什么 github 没有 ui,我们必须不断修改 url (9认同)
  • 哦,似乎有一个[2点](https://help.github.com/articles/about-comparing-branches-in-pull-requests/#three-dot-and-two-dot-git-diff -comparisons)表示更多信息的符号. (4认同)
  • @AlikElzin-kilaka,“3 个点”将从最后一个公共提交进行比较:`git diff $(git merge-base AB) B`。“2 点”直接比较两个提交:`git diff AB`。类似于 `git diff A...B` 与 `git diff A..B` (4认同)

wis*_*cky 13

TLDR:只需在 URL 末尾添加 /compare。

您可以使用 Github 比较 UI,它会为您生成 URL。用你的价值观替换ORGREPO。UI 仅列出分支,但您也可以输入任何有效的标签(例如v1.0.0)或提交 ID(例如1a2b3c)。

https://github.com/ORG/REPO/compare/

在此处输入图片说明


生成的 URL 就是这种格式。您还可以使用 REF 手动编辑 URL。

https://github.com/ORG/REPO/compare/REF1...REF2

您还可以使用“2 点”(直接差异)而不是“3 点”(与上次常见提交的差异)。与git diff A..Bvsgit diff A...B相同。

https://github.com/ORG/REPO/compare/REF1..REF2

如果要跨分叉进行比较,则需要添加 ORG2:

https://github.com/ORG/REPO/compare/REF1...ORG2:REF2

有文档,但我认为不是很清楚:https : //help.github.com/en/github/committing-changes-to-your-project/comparing-commits-across-time


Sch*_*ern 5

您链接的文章有比较提交的说明。

GitHub 比较工具将接受任何修订。分支、标签、提交 ID,甚至日期。如果您想比较两个提交,请为其提供提交 ID。这是他们的例子

  • @gseattle https://github.com/alpacahq/pylivetrader/compare/v0.0.27..v0.0.28 (2认同)