1

I have a pull request that is currently against the master branch and I want to change its base to a branch that is two commits behind master.

When I change the base branch in GitHub Enterprise the two commits that are not on master also get dragged into the pull request.

Is there a way to change the base branch but just have the commits that are actually in the pull request? I don't see any options other than the branch name, and my commit and one of the other commits touches the same file but not the same lines.

tschumann
  • 2,776
  • 3
  • 26
  • 42
  • Changing the base branch just changes which branch you're comparing (and will merge) *to*, it doesn't change the content of the branch you're merging *from*. It sounds like you need to drop those two commits, in which case an interactive rebase will let you do it. – jonrsharpe Aug 19 '20 at 06:46
  • Does this answer your question? [Delete commits from a branch in Git](https://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git) – jonrsharpe Aug 19 '20 at 06:46
  • @jonrsharpe I know I can do an interactive rebase - I was just hoping that GitHub would give me an easy option. I just want to change the branch my pull request gets merged to, I don't want all the differences between the old and new branches to come with it. – tschumann Aug 19 '20 at 07:01
  • That doesn't make sense. Git(Hub) is just going to try to merge whatever's on the source branch into whatever's on the target branch. A branch is just a pointer to a commit, which has parents, which have parents, which... Again, changing the target **does not** change the source, and those two commits *are* on the source branch. – jonrsharpe Aug 19 '20 at 07:06
  • @jonrsharpe GitHub knows what is part of the pull request and what isn't. https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/changing-the-base-branch-of-a-pull-request also says "When you change the base branch of your pull request, some commits may be removed from the timeline". – tschumann Aug 19 '20 at 07:32
  • Yes, of course it knows what's involved. But it doesn't know you didn't want to include those commits. When it talks about commits being removed as the base changes, it means because there could be more shared history, e.g. if you changed source with commits ABCD from target AB to target ABC - C would be disappear from the merge, because now it's already there. But if you switch the target back from ABC to AB, you *gain* a commit in the merge, because C now needs to be included. – jonrsharpe Aug 19 '20 at 07:41

0 Answers0