First, make a backup, in case something goes wrong. Clone your repository as <repository>-backup
with -b <branchname>
and don't touch that one.
Second, find the commit hash of the last good commit in git log
.
Then run:
git push --force origin <last good commit hash>:<branch>
Note that rewriting history is generally considered a bad idea, unless you're the only user of the repository. If other people have pulled down the repository with a commit change, and you force push and remove that commit, the repository will enter a corrupted state.
Unless you pushed some sensitive information you really need to remove, just revert the commit with:
git revert <commit hash to revert>
git push