32

I have created a pull request from my master branch to upstream and now every new commit on that branch automatically attaches itself to this pull request.

There was a "Change commits" button on pull request page at the time of creation but it seems to disappear after request is created. Can I do it some other way now ?

Marcin Wisnicki
  • 4,511
  • 4
  • 35
  • 57
  • 4
    You should always create a separate feature branch for each pull request. – Tapio Jul 27 '12 at 11:06
  • You can hard reset your current branch and force-push it to return the PR to a previous commit, and create new branches for future PRs. – jessehouwing Feb 25 '20 at 14:49
  • 1
    @Tapio while true, does this answer the question? If you make a new branch "feature x" and keep committing to that branch after a pull request, those commits would be added to the original request, no? – actual_panda Mar 26 '20 at 07:04

1 Answers1

5

In GitHub a Pull Request denotes the request to merge one branch with another. When either branch is updated, the pull-request is updated too and the merge is re-evaluated.

Thus, when you push new changes to a branch that has an outstanding pull request linked to it, the pull request will be updated to include the new changes.

To reset your pull request to a previous state you can:

   git switch branch-you-want-to-fix
   git branch backup-of-later-changes
   git reset --hard hash-of-desired-changes
   git push --force

This will create a new local branch with your later changes and will remove those changes from the branch on github.

The pull-request will be re-evaluated (one of its sides has been updated with your force push), and you can create a new pull request from your backup-of-later-changes branch.

As long as the new commits aren't pushed to the pr-branch, they won't automatically appear in it, even if these changes are based on top of your original pr-branch.

rturrado
  • 7,699
  • 6
  • 42
  • 62
jessehouwing
  • 106,458
  • 22
  • 256
  • 341