You may forcibly override a branch on a remote git server, including github:
git push -f <server> <good_state>:<target_branch>
Use with care.
Perhaps more comprehensive explanations are required.
Suppose you have a repo on github. In the local clone of the repo there're commits:
A -> B -> C -> D -> E
in a branch <Branch>
(it could be master
, or whatever), where E
commit is "bad" (wrong, contain some erroneous or sensitive data etc). You have already pushed this branch to github
and even created a pull request in some "parent" project.
First of all, remove the pull request, to prevent accidental merge of the E commit.
Then, drop E
from your published commits on github:
git push -f github <D>:<Branch>
Now on github the <Branch>
ends with <D>
commit as if there wasn't <E>
at all. Now you can fix <E>
locally, by issuing git commit --amend
, or simply drop it with git reset --hard <D>
. Whenever you're ready, you may push the new commits again and repeat PR.