Reputation: 2121
I accidently did a
git push --force
on a public repository and reverted to previous commits. How to a fix this issue? I still have the correct versions on my local computer but not able to push them onto the github repository, it says that everything is up to date. I know this was very stupid of me!
Upvotes: 2
Views: 263
Reputation: 124734
Relax, if you have the commit that was the original HEAD before you overwrote it, you can git push --force
it back. It's just a matter of telling it to git
the right way.
You are getting "everything is up to date" because you are not telling it right. When that happens, it's pushing not what you think.
Find either the branch you want to re-push, or even just the commit (sha) that you want to re-push. Assuming the name of your github remote is "origin", and assuming you want to fix "master", you can push back like this:
git push origin the_branch:master --force
or even:
git push origin the_sha:master --force
But before you do that, I recommend to double-check with a diff:
git diff the_branch..origin/master
or
git diff the_sha..origin/master
or replace diff
in the above with rev-list
to see the list of commits that will be pushed.
Upvotes: 1