git 在最初创建提交的 Github 上查找拉取请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17818167/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:37:07  来源:igfitidea点击:

Find a Pull Request on Github where a commit was originally created

gitgithubpull-request

提问by DragonFax

Pull Requests are great for understanding the larger thinking around a change or set of changes made to a repo. Reading pull requests are a great way to quickly "grok" a project as, instead of small atomic changes to the source, you get larger groupings of logical changes. Analogous to organizing the lines in your code into related "stanzas" to make it easier to read.

拉取请求非常适合理解对存储库所做的更改或一组更改的更大思考。阅读拉取请求是快速“理解”项目的好方法,因为您可以获得更大的逻辑更改分组,而不是对源进行小的原子更改。类似于将代码中的行组织成相关的“节”以使其更易于阅读。

I find myself looking at a file or a commit, and I wonder if there is a way to backtrack the commit to the Pull Request that originally created it. That Pull Request would have been merged eventually, but not necessary with a merge-commit.

我发现自己正在查看一个文件或一个提交,我想知道是否有办法将提交回溯到最初创建它的拉取请求。该拉取请求最终会被合并,但不需要合并提交。

回答by RustyToms

You can just go to github and enter the SHA into the search bar, make sure you select the "Issues" link on the left.

你可以去 github 并在搜索栏中输入 SHA,确保选择左侧的“问题”链接。

UPDATED 13 July 2017

2017 年 7 月 13 日更新

Via the Github UI there is a now a really easy way to do this. If you are looking at a commit in the list of commits in a branch in the UI, click on the link to the commit itself. If there is a PR for that commit and it wasn't added directly to the branch, a link to the PR listing the PR number and the branch it went into will be directly under the commit message at the top of the page. enter image description here

通过 Github UI,现在有一种非常简单的方法可以做到这一点。如果您正在查看 UI 中某个分支的提交列表中的某个提交,请单击该提交本身的链接。如果该提交有 PR 并且它没有直接添加到分支,则列出 PR 编号和它进入的分支的 PR 链接将直接位于页面顶部的提交消息下方。 在此处输入图片说明



Example of finding a PR by clicking on a link to the commit

通过单击提交链接查找 PR 的示例

If you have the commit SHA and nothing else and don't want to go digging around for it, just add /commit/[commit SHA]to the repo url, and you will see the commit page, with the PR link if it exists. For example, if the SHA is 52797a7a3b087231e4e391e11ea861569205aaf4 and the repo is https://github.com/glimmerjs/glimmer-vm, then go to https://github.com/glimmerjs/glimmer-vm/commit/52797a7a3b087231e4e391e11ea861569205aaf4

如果您有提交 SHA 而没有其他内容并且不想四处寻找它,只需添加/commit/[commit SHA]到 repo url,您将看到提交页面,如果存在 PR 链接。例如,如果 SHA 是 52797a7a3b087231e4e391e11ea861569205aaf4 并且 repo 是https://github.com/glimmerjs/glimmer-vm,则转至https://github.com/glimmerjs/glimmer-vm/commit/5279016e7a2831a4e631a831af4

回答by qqx

git config --add remote.origin.fetch +refs/pull/*/head:refs/remotes/origin/pull/*
git fetch origin
git describe --all  --contains <COMMIT>

If necessary, change originto the name of the remote that points to the github repository to which the pull request would have been sent. The first command only needs to be run once for any given remote, and the second will generally be done when getting other updates.

如有必要,请更改origin为指向拉取请求将发送到的 github 存储库的远程名称。第一个命令只需要为任何给定的远程运行一次,第二个命令通常会在获取其他更新时完成。

This will cause git to get information about pull requests along with actual branches. They'll show up as remote-tracking branches like origin/pull/123. Once that is done you can use git describewith the --alland --containsoptions to show the first branch which has the referenced commit.

这将导致 git 获取有关拉取请求以及实际分支的信息。它们将显示为远程跟踪分支,如origin/pull/123. 一旦做到这一点,您可以使用git describe--all--contains选项,以显示它具有引用提交第一家分店。

However, this won't work if the commit you're looking for is actually a modified version of the commit from the pull request such as if the changes were rebased onto other work or the person doing the merge decided to make some changes.

但是,如果您要查找的提交实际上是来自拉取请求的提交的修改版本,则这将不起作用,例如如果更改重新基于其他工作,或者进行合并的人决定进行一些更改。

回答by VonC

Since Oct. 13, 2014, this should be straightforward:

自 2014 年 10 月 13 日起,这应该很简单:

For example:

例如:

You can see for the file hakimel/reveal.js/plugin/markdown/markdown.js, my contributionnow comes with a reference to the PR #734it originated.

你可以看到这个文件hakimel/reveal.js/plugin/markdown/markdown.js我的贡献现在带有对它起源的PR #734的引用。

PR from contrib

来自贡献的公关

This comes from Linking merged pull requests from commits:

这来自从提交链接合并的拉取请求

We've been including the containing branches and tags on commit pagesto give you more context around changes. Now, commits in a repository's default branch will also show you the pull request that introduced them.

我们一直在提交页面上包含包含分支和标签,以便为您提供有关更改的更多上下文。现在,存储库默认分支中的提交还将向您显示引入它们的拉取请求。

commit with PR reference in it!

在其中提交公关参考!

In the pull request, you can see the discussion around why the commit was introduced, and get a clearer picture of the reason for the change.

As always, if you know the commit SHA, you can skip the commit page and search for the pull request directly.

在拉取请求中,您可以看到关于为什么引入提交的讨论,并更清楚地了解更改的原因。

与往常一样,如果您知道提交 SHA,则可以跳过提交页面并直接搜索拉取请求

回答by Dan Rosenstark

Put the commit hash into the Pull Request filters field on GitHub.

将提交哈希放入 GitHub 上的拉取请求过滤器字段。

enter image description here

在此处输入图片说明

回答by Joey

I had this same problem and wrote the pr_for_sha bash helper, documented here:

我遇到了同样的问题并编写了 pr_for_sha bash helper,记录在这里:

http://joey.aghion.com/find-the-github-pull-request-for-a-commit/

http://joey.aghion.com/find-the-github-pull-request-for-a-commit/

Call it like pr_for_sha <COMMIT>and it will open the corresponding github pull request page in a browser.

调用like pr_for_sha <COMMIT>,它会在浏览器中打开对应的github pull request页面。