1

For a PR with number 1 GitHub automatically creates a ref refs/pulls/1/head and refs/pulls/1/merge. The latter contains the result of the merge and is especially useful for e.g. CI (because what you want to test is actually the result of the merge).

After merging a PR, the refs/pulls/<number>/merge is no longer available (I suppose because the PR is no longer mergeable). Currently I want to run a test on a version that was merged a while ago. Is there an easy way to access the result of the merged PR, given just the PR number?

Martijn
  • 5,491
  • 4
  • 33
  • 41
  • 1
    Perhaps I did not made myself clear. The problem is that I'm actually looking for the merge commit (e.g. its sha), given just the PR number. – Martijn Jun 04 '15 at 12:43

1 Answers1

1

The following should do the trick even though you should be aware that there are possibly multiple "children" of a commit (someone else could base work on the PR and merge it into master again later):

$ git rev-list -n1 upstream/pull/<number>..upstream/master

This works by getting the first commit walking from upstream/pull/<number> to upstream/master. Luckily github leaves upstream/pull/<number> just on the last commit of the PR.

Here's an example of https://github.com/RDFLib/rdflib:

It's current history looks like this:

* 371263f - (upstream/pull/486) Removed debugging print statement
...
*   fe3fa52 - (upstream/master, upstream/HEAD) Merge pull request #482
|\
| * 354c352 - (upstream/pull/482) fix broken example
|/
*   f81e0b2 - Merge pull request #480
....

Here some test output:

$ git rev-list -n1 upstream/pull/482..upstream/master
fe3fa522b48e787fa87dc1156e1a10bd6671b62c
$ git rev-list -n1 upstream/pull/486..upstream/master
(no output)
Jörn Hees
  • 3,338
  • 22
  • 44