3

When I create a pull request, I can choose which branch to base it on.

I am also able to specify a commit as "base branch" (as well as tag and history marker).

I want to use a commit instead of a master to make the owner of the repository aware of the fact that the master is not compilable and that I have already locally based my work on that commit.

enter image description here If I change from using the remotes master to using a commit (that exists remotely), by entering a SHA1 hash in the textfield of the dropdown, the diff will be correct, but the "create pull request" button will not be there any longer.

Why not?

Edit

As a response to a response that it would result in a detached HEAD.

What the remote repository looks like:

-C1-C2-M

What my repository looks like:

-C1-C2-R/M
   \ 
    MyC3-MyBranch

What I want the remote repository look like:

-C1-C2-M
   \ 
    MyC3-MyBranch

How is that detaching HEAD?

Community
  • 1
  • 1
Anders Lindén
  • 6,839
  • 11
  • 56
  • 109

3 Answers3

3

Because the maintainer could not accept (merge) the PR into one of his/her branch.

Merging a PR branch to a commit would create a detached HEAD.

I mean that on the maintainer side of course:

Your own repo would not have any detached HEAD: your PR branch can start from any commit it wants.
But the original repo has no branch at the commit you used to start your PR branch.

As a result, said PR branch could not be merged on top of the original repo branch, because again there is no branch to merge to (on the original repo side, not on your side).
Merging (on the original repo side) a branch onto a commit (instead of onto an existing branch) would create a detached HEAD, ie a commit (result of the merge) which is referenced by no branch (in that original repo).

The goal of a PR is to integrate/merge a PR branch into an existing branch of an original repo, not to create/add a new branch (MyBranch).


You would need to request from the maintainer of the original repo to create a branch first from that commit, in order for you to use this branch for your PR.

As an alternative:

  • start your PR branch from master,
  • add a revert commit which reverts to the commit you want to start (git revert),
  • then add your fix commits
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • How would HEAD become detached? – Anders Lindén Jun 12 '16 at 07:29
  • @AndersLindén That is what the link I mention in the answer (http://stackoverflow.com/a/3965714/6309) explains: you would create a new commit on top of a commit instead of on top of a branch. That new commit would not be referenced by any branch: detached HEAD. – VonC Jun 12 '16 at 07:30
  • @AndersLindén why can I choose a commit as "base branch"? Because you can diff between any ref (commit or branch). But only a branch is a candidate for a PR, as I explain above. – VonC Jun 12 '16 at 07:34
  • @AndersLindén I have edited my answer to make crystal-clear that the "detached HEAD" issue is not affecting your repo, but the original repo that would try to receive your PR. – VonC Jun 12 '16 at 07:45
  • So HEAD remotely would not point to MyBranch after the PR has been merged? – Anders Lindén Jun 12 '16 at 07:49
  • @AndersLindén No it would most certainly not: again (as I just edited), the goal of a PR is to contribute to an *existing* branch of a repo, not to add many branches from many PRs. – VonC Jun 12 '16 at 07:50
  • As I see it, nothing can be based on master as it is now. The goal with my PR was not the one you describe. Your point is however taken. – Anders Lindén Jun 12 '16 at 07:52
  • @AndersLindén That is why my answer suggests to contact the maintainer and request for him/her to create a branch. – VonC Jun 12 '16 at 07:58
  • @AndersLindén To illustrate my previous point, a project like docker has 9000+ merged PR. That did not resulted in 9000+ new branches ;) (https://github.com/docker/docker/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+is%3Amerged) – VonC Jun 12 '16 at 07:59
  • I only suggest new branches in cases like this. When someone wants to base their work on a commit instead of a branch. – Anders Lindén Jun 12 '16 at 08:01
  • @AndersLindén There is no "situation like this" because any PR is done from a branch. In your case, as an alternative: start from master, add a revert commit which reverts to the commit you want to start, then add your fix commits. – VonC Jun 12 '16 at 08:02
  • Then I wonder why I was able to enter a SHA1 hash as remote branch to base a PR on to start with. I though it was a good idea (still thinking that). – Anders Lindén Jun 12 '16 at 08:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/114451/discussion-between-vonc-and-anders-linden). – VonC Jun 12 '16 at 08:06
  • @AndersLindén it not a good idea from the maintainer point of view (see my docker example). You can enter a SHA1 because you can make a diff from any commit. You can start a PR only from a branch though. – VonC Jun 12 '16 at 08:07
  • @AndersLindén I have edited the answer with a valid alternative which allows you to move forward with this, without even having to contact the maintainer. – VonC Jun 12 '16 at 08:08
1

I had trouble with this, as well. I honestly believe it is some sort of glitch on the part of gitHub. The "Create Pull Request" button just disappeared.

In my case, I was trying to merge a specific commit from a "develop" branch into master.

The solution I found was to pull down a local branch of the commit that I wanted and then push my local branch up to master and create a PR that way. Easy work around.

Forrest
  • 2,968
  • 1
  • 27
  • 18
-1

Merge request is applied on top of branch. The committer can not apply patch of merge request when it is associated to some history moment instead of top of branch.

If you have see that branch to commit to changed you need to rebase your branch to branch to merge. And after this rebase do pull request.

oklas
  • 7,935
  • 2
  • 26
  • 42