Skip to content

Instantly share code, notes, and snippets.

@robertpainsi
Last active November 13, 2024 08:04
Show Gist options
  • Save robertpainsi/2c42c15f1ce6dab03a0675348edd4e2c to your computer and use it in GitHub Desktop.
Save robertpainsi/2c42c15f1ce6dab03a0675348edd4e2c to your computer and use it in GitHub Desktop.
How to reopen a pull-request after a force-push?

How to reopen a pull-request after a force-push?

Precodinitions

  • You need the rights to reopen pull requests on the repository.
  • The pull request hasn't been merged, just closed.

Instructions

  1. Write down the current commit hash of your PR-branch git log --oneline -1 <PR-BRANCH>
  2. Write down the latest commit hash on github before the PR has been closed.
  3. git push -f origin <GITHUB-HASH-FROM-STEP-2>:<PR-BRANCH>
  4. Reopen the PR.
  5. git push -f origin <HASH-FROM-STEP-1>:<PR-BRANCH>

Example

You've a PR branch my-feature currently at 1234567. Looking at the the PRs page, we see that the PR was closed when my-feature pointed at 0abcdef.

  • git push -f origin 0abcdef:my-feature #pushing the old commit the PR has been closed with
  • Reopen the PR.
  • git push -f origin 1234567:my-feature #pushing the latest commit
@prateek-agrawal
Copy link

prateek-agrawal commented Sep 23, 2020

I was getting error in the steps above. I was able to resolve it using github by following below steps

  1. Got to <code>
  2. In Branch drop down list , select your closed branch. Example : <bug-id>.<base-branch>
  3. Then click on New pull request
  4. Under base drop down select the <base-branch> where you want to commit your code and then you are good to go.

@srikanth-vnv
Copy link

Thanks @robertpainsi. It saved my day.

@stas00
Copy link

stas00 commented Dec 9, 2020

Awesome!

In my case steps 1 and 2 both had the same sha, so this didn't work.

I fixed that by:

  1. creating a tiny change and pushing a new commit to the closed PR branch
  2. reopening PR
  3. force pushing commit from step 2 (the last sha before PR was closed)

That did the trick. Thank you for that idea, @robertpainsi!

@robertpainsi
Copy link
Author

@mlatysh1: Sorry for the very late response. In your image it states

…no longer has any new commits. Pushing new commits will allow the pull request to be re-opened.

Please try @stas00 instructions and let me know if it works.

@jayTandalaiRally
Copy link

worked for me. thank you so much!

@Gammal-Skalbagge
Copy link

very helpful and easy to find. thank you!

@iMonZ
Copy link

iMonZ commented Sep 2, 2021

Thank you so much, you saved my day!

@chadthompsonallscripts
Copy link

When you do a soft reset in order to squash commits, then forget to commit and force push the branch, it closes the PR with this error. Thank you for this, as with everyone else here, I'll chime in that this saved the day.

@jswny
Copy link

jswny commented Oct 25, 2021

Amazing 🎉

@heesuk-ahn
Copy link

Thanks your sharing!

@akbortoli
Copy link

Thank you for sharing.

@JemarJones
Copy link

Thank you for the tip!

@Ed6ar
Copy link

Ed6ar commented Mar 3, 2022

Thanks master.

@damiendillon
Copy link

Thank you!!

@mochadwi
Copy link

Thank youuuu!

@Mirko-Weiler
Copy link

Thanks!

@natalia-tamy
Copy link

Thank you so much!

@allblueee
Copy link

thx! life saver!

@sqiuChime
Copy link

👍 👍 👍

@omarY23
Copy link

omarY23 commented Mar 20, 2023

Thanks alot!

@ayeankit
Copy link

Thanks a lot. This saved my day.

@sumayaSalihs
Copy link

Thanks a lot. This was so helpful.

@pljones
Copy link

pljones commented Apr 19, 2023

Brilliant! Thanks!

@hinell
Copy link

hinell commented Apr 22, 2023

How come that devs at github fucked up so hard, so we have to push/pull forth and back just to make PR working?

@koenigr
Copy link

koenigr commented Jun 13, 2023

Thank you very much !!!!

@jw3215
Copy link

jw3215 commented Jun 16, 2023

Thanks a lot !!!

@zyqxd
Copy link

zyqxd commented Jan 3, 2024

This issue essentially is due to your PR and your origin branches having mismatching histories (caused by a force push after that PR closed). If your PR has multiple commits, you may need to reset the entire branch. For example

If your PR commit history is:

sha-0123 <- head
sha-1234
sha-2345

But your origin branch history is

sha-3210 <- head
sha-4321
sha-5432

You need to do reset your origin head to sha-0123, then force push your new history head to sha-3210:

# if you don't have commit `sha-0123`;
git fetch sha-0123
git co FEATURE-BRANCH
git reset sha-0123 --hard
git push --force
# **You should be able to reopen your PR at this point**
# reset to `sha-3210` on the same branch
git reset sha-3210 --hard
git push --force

@stceum
Copy link

stceum commented Jan 27, 2024

Thanks a lot !

@gocklkatz
Copy link

Thanks a lot !

@dcolinmorgan
Copy link

honest pretty freaking awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment