gitgithubpull

Git refs merge vs head in pull request


The refs/pull/*/head refers to head of the PR but what about the refs/pull/*/merge, I am not finding any git commits which are shown as part of /merge in commit history. What does this /merge exactly mean for a PR and when PR has multiple commits to it, when PR is open, When PR is closed etc

$ git ls-remote
From git@<repo url>
01c8cd97857c21cfc5d413bd64e3c0e8cc8fd03d        HEAD
37b88346a9edb426f676d080be502a1d4349c499        refs/heads/PR1
6fda26f078c00adf518ec620e94f54daa85bb894        refs/heads/PR1-1
bd88e471db4127f066b3b2f1d699b8296ca62f6d        refs/heads/PR5
25b5eec47ca186a778c93439cd81e8a4125b5d6f        refs/heads/PR6
58a82cf11218991f8f544a14ef6c57d3963690ee        refs/heads/PR7
a5831973e1a4561527551a8bc8a9d5f9436f004b        refs/heads/Pr2
01c8cd97857c21cfc5d413bd64e3c0e8cc8fd03d        refs/heads/develop
442c0bc7f8b3872660d48cbd42690be677314b94        refs/heads/master
37b88346a9edb426f676d080be502a1d4349c499        refs/pull/1/head
2db24e8a6a53ce006694c4c5db1886df44620372        refs/pull/1/merge
a5831973e1a4561527551a8bc8a9d5f9436f004b        refs/pull/2/head
4ea1814dda65e2ca8572fbbc5da9cc8141391ab8        refs/pull/2/merge
6fda26f078c00adf518ec620e94f54daa85bb894        refs/pull/3/head
b6cde57523fc73ce08dd7e588eeb606c3f047136        refs/pull/3/merge
442c0bc7f8b3872660d48cbd42690be677314b94        refs/pull/4/head
58a82cf11218991f8f544a14ef6c57d3963690ee        refs/pull/5/head
e4a82d455b8b8e81b70dfbf4f6d79a1fb5158cbb        refs/pull/5/merge
bd88e471db4127f066b3b2f1d699b8296ca62f6d        refs/pull/6/head
e8825e286aa9c36c04046c5d4ac85c9d7a4ebf5c        refs/pull/6/merge
25b5eec47ca186a778c93439cd81e8a4125b5d6f        refs/pull/7/head
ed262d8c4766b037207f3113b634c777b3a0af37        refs/pull/7/merge

for ex.

25b5eec47ca186a778c93439cd81e8a4125b5d6f        refs/pull/7/head
ed262d8c4766b037207f3113b634c777b3a0af37        refs/pull/7/merge/

what is the significance of ed262d8c4766b037207f3113b634c777b3a0af37 refs/pull/7/merge/ and this commit id ed262d8c4766b037207f3113b634c777b3a0af37 is not found anywhere


Solution

  • The refs/pull/<number>/merge is a reference created by GitHub to keep track of what would happen if a pull request was merged. It references the merge commit between refs/pull/<number>/head and the destination branch (e.g. master).

    You can think of it as a "future" commit. GitHub (as well as other Git-based collaboration platforms) use this technique to determine whether the pull request would successfully merge with all the checks passing and no merge conflicts.

    Atlassian has a good explanation of the reasoning behind this server-side implementation detail here:

    When you view a pull request, you’re seeing what the resultant merge commit will actually look like. We do this by actually creating a merge commit behind the scenes, and showing you the difference between it and the tip of the target branch.

    They're obviously talking about Bitbucket, but the same applies to GitHub.