228

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

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

4

6 回答 6

291

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

UPDATED 13 July 2017

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


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

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

于 2014-09-18T14:04:13.217 回答
63
git config --add remote.origin.fetch +refs/pull/*/head:refs/remotes/origin/pull/*
git fetch origin
git describe --all  --contains <COMMIT>

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

这将导致 git 获取有关拉取请求以及实际分支的信息。它们将显示为远程跟踪分支,例如origin/pull/123. 完成后,您可以使用git describeand--all选项--contains 来显示具有引用提交的第一个分支。

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

于 2013-07-23T19:11:24.183 回答
23

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

例如:

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

来自 contrib 的 PR

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

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

提交 PR 参考!

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

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

于 2014-10-15T07:50:22.410 回答
17

将提交哈希放入 GitHub 上的 Pull Request filters 字段。

在此处输入图像描述

于 2017-08-15T16:43:32.250 回答
3

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

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

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

于 2014-06-20T16:40:57.373 回答
1

I've been a heavy user of the cheeky little link on the GitHub web UI but wanted a faster way that would take me straight there from the terminal, basically a git pr SHA command. It took a bit of doing, but here's a series of git aliases that will set that up for you on MacOS:

  git config --global alias.merge-commits '!funct() { git log --merges --reverse --oneline --ancestry-path $1..origin | grep "Merge pull request";  }; funct'
  git config --global alias.pr-number '!funct() { git merge-commits $1 | head -n1 | sed -n "s/^.*Merge pull request #\\s*\\([0-9]*\\).*$/\\1/p"; }; funct'
  git config --global alias.web-url '!funct() { git config remote.origin.url | sed -e"s/git@/https:\/\//" -e"s/\.git$//" | sed -E "s/(\/\/[^:]*):/\1\//"; }; funct'
  git config --global alias.pr '!funct() { open "`git web-url`/pull/`git pr-number $1`" ;}; funct'

If you're on Linux, replace open with xdg-open and you're golden. It shouldn't be too difficult to adapt to work with GitLab either.

Note this will only work if you practicing GitHub flow and creating explicit merge commits.

I've written a more detailed explanation of how this all works here: https://tekin.co.uk/2020/06/jump-from-a-git-commit-to-the-pr-in-one-command

于 2020-10-23T16:40:15.567 回答