Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I find a specific pull request on GitHub?

Click Create Pull Request. GitHub Desktop will open your default browser to take you to GitHub. On GitHub, confirm that the branch in the base: drop-down menu is the branch where you want to merge your changes. Confirm that the branch in the compare: drop-down menu is the topic branch where you made your changes.

How do you check on which branch commit was made?

Search the reflogs If you're not working in the repository where the commit was made, the best you can do in this case is examine the reflogs and find when the commit was first introduced to your repository; with any luck, you fetched the branch it was committed to.

How can I see the code of a previous commit?

To view the previous commits, use the git log –-oneline command. This provides the commit details.


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


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

If necessary, change origin to 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.

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 describe with the --all and --contains options to show the first branch which has the referenced commit.

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.


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

For example:

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

PR from contrib

This comes from Linking merged pull requests from commits:

We've been including the containing branches and tags on commit pages to 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.


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

enter image description here


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

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.


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