GitHub: Reopening a merged pull request
Asked Answered
L

10

180
  • I made some changes
  • I submitted a pull request
  • The pull request was accepted and merged.
  • We found a bug
  • The changes were removed again (force push to 1 commit before) whilst I fixed the bug.

I've now fixed the bug and want to resubmit the pull request with 1 extra commit. Is there any way to reopen the pull request or update it, or do I have to create a new pull request, type out the description etc again? Gitorious has this feature and we've recently moved to GitHub.

Lancaster answered 1/10, 2012 at 13:30 Comment(1)
I was in similar situation today i.e. used "Merge Pull Request" button which by default merge the changes into target branch and close the PR. I later discovered a bug in testing which I wanted the original developer to fix. I wanted a way to reopen this PR so that more commits can be added to this same PR but could not as there is no button for reopening the PR.Contemporize
L
178

The answer seems to be: You can't.

Once a pull request is merged and closed, it is locked forever and cannot be reopened. If your pull request is merged, closed, then your changes are pulled out (via force pushing backwards to before the merge), you will need to add commits to the branch and create a new pull request, copying all the details over and probably providing a link to the original pull request to manually save the history.

Might be a nice feature request for future GitHub.

Lancaster answered 11/10, 2012 at 11:11 Comment(6)
I don't know when it was changed, but you can comment & reopen closed PRs now.Diplomacy
@LB, it doesn't seem you can reopen PRs that have been closed and merged.Danialah
You actually can. Assuming that you have reverted the initial merge, you can make a branch of the main repo, and on this new branch just revert the commit that was reverting the merge.Peckham
@SsjCosty But that is not reopening a closed & merged PR. You can always open new pull requests, which is what your solution requires.Maseru
"Might be a nice feature request for future GitHub." Actually, no, it wouldn't. If PRs could be redefined after creation, then people checking out the PR at different times, would potentially drift. Just create another PR and "mention" the prior one in text. If you want to reference some sort of milestone, it's not PRs to look at, that would be tags.Traumatism
@ScottPrive let me clarify the situation. The original PR was merged into a branch that no longer exists. Master has been forced pushed backwards in the past so the merge commit no longer exists. There is no use looking at a merged PR from a branch to master where the merge commit doesnt exist any more, and having 2 identically named PRs from + to the same branches is more confusing than simply re-opening the original.Lancaster
A
11

I just successfully reopened a pull request by

  1. Commenting on the pull request
  2. Clicking the 'Submit and re-open' button which appeared on the comment form.
Allopathy answered 1/10, 2012 at 13:30 Comment(5)
I haven't managed to replicate this - can you explain the steps required to see this behaviour? I tried commenting on a closed pull request (didnt work), commenting on a closed pull request and pushing to the branch it was pulling in (didnt work). Anything else to try? Is the pull request required to be merged then later unmerged somehow?Lancaster
I don't know what the hidden requirement making a difference is. Could be any of (have submitted new change for pull request, am member of project owners, other...)Allopathy
I've now tried everything you mentioned, still can't see it. I am the repo owner. Searching google for "Submit and re-open GitHub" provides a single hit - this page. Any further information would be extremely helpful. Was your pull request initially denied?Lancaster
I can replicate this with unmerged pull requests - but that's not what this thread is about.Thimble
Yeah, he is referring to closed pulls, not merged pulls.Flats
R
4

You can use the revert action:

enter image description here

It will create another pull request undoing all the changes did in the merged PR.

Realism answered 21/11, 2016 at 13:33 Comment(6)
This is not the best practice :)Otisotitis
@Otisotitis can you suggest a better approach?Realism
Let's assume, we had merged pr with commits (mA and mB) to stable branch that we want to revert. After merging "revert" pr, history will look like tree of commits: X-Y-mA-mB-C-D-rA-rB-E-F. Why do you want to see all of these commits in history, that apply changes (mA, mB) and then cancel them (rA, rB)? It would be better to rebase and remove those "bad" commits mA and mB from stable branch and keep history clean. Of course, it makes sense if merge was relatively recent.Otisotitis
Not only will the history look ugly, you also can no longer simply merge the reverted commits back in when you are ready.Chromato
I had somewhat similar scenario with minor difference. I had a PR that I needed to review and was supposed to wait for another PR to be merged. But I didn't see it and merged this PR prematurely. I actually did what @WilliamWeckl suggested. But now I want to create the same PR with same changes that were created originally. But when I am creating the PR the master branch is showing no difference, though when I see individual files they are different. Any thoughts?Nightdress
I think this "Revert" button serves a different purpose than what the OP originally is asking which is reopening for adding extra commits to the original PR. Instead, this "Revert" button is actually "undoing" the PR and start the entire thing over?Stylistic
A
4

I've tried all of the tricks & tips. Simply - you can't re-open it.

It is what it is. (even that I'm sad they haven't come up with this)

Astronomical answered 15/11, 2021 at 7:56 Comment(0)
G
4

Edited by the author to add: It's 2023, and consensus seems to be this never works.


Well, it's 2021 and—almost a decade later—to my dismay, stupor, and joy, a simple gh pr reopen N¹ did reopen my PR—in a situation which I know was un-reopenable through UI before (or so I believe). ¯\_(ツ)_/¯

May this work for you too!

(¹) gh being GitHub’s official command line tool.

Gipsy answered 22/12, 2021 at 8:49 Comment(7)
Was the PR already merged before you tried to reopen it?Lancaster
Yes. (Not with the merge button: the base branch had been accidentally pushed to including the commit from the PR.) The base branch was later force-pushed back to its original state, but the PR could not be reopened, not by any means I tried.Gipsy
Pull request #20 (LOTH Prose) can't be reopened because it was already merged - did you have any extra commits or anything?Kerf
Mine was already merged and the above trick didn't work for me either.Diwan
fwiw you can still push to the branch and then open a new pull request on the updated branch. I did this (even after deleting the branch) by first pushing to it then listing branches with "view all branches" in the branches dropdown in the code tab. There's an option to create a pull request for each branch.Alloplasm
Doesn't work on PRs already merged, even though the base was reset to before the merge commit.Hectoliter
Yeah, didn't work for me (despite the PR having been merged automatically by pushing to the base branch and having force-pushed the branch back)... got: X Pull request #37 (Update to node 18) can't be reopened because it was already mergedVolitant
C
3

Just derive a new branch from the existing branch where you have done extra 1 commit. From there submit the pull request.

Computerize answered 15/11, 2013 at 6:33 Comment(2)
That would result in a new pull request with none of the history for the original.Karajan
This is what I ended up doing. Yes the history is less linear but it is ok for me.Bondie
O
3

You could just revert a reverted PR, this should have all the changes that was reverted from original PR.

Oliphant answered 22/1, 2021 at 8:2 Comment(0)
D
1

I managed to reopen it by:

  1. Restoring the base branch
  2. Reopen and Comment
Dismuke answered 7/4, 2021 at 11:50 Comment(0)
A
0

A PR that has been shut down will now reopen a button:

enter image description here

Aarika answered 8/10, 2023 at 9:15 Comment(1)
But that screenshot you added displays a "Close pull request" button, not a "Reopen pull request" button. You should probably edit your answer to show a more appropriate image that demonstrates your claim.Stidham
O
-1

Its 2023 now, you can reopen a pull request with just a click in the bottom left. Further, you can edit the comment as you wish. Thank you!

Oread answered 16/11, 2023 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.