Question:
I “accidentally” pushed a commit to GitHub. Is it possible to remove this commit? I want to revert my GitHub repository as it was before this commit.
Answer:
First, remove the commit on your local repository. You can do this using git rebase -i. For example, if it’s your last commit, you can do git rebase -i HEAD~2 and delete the second line within the editor window that pops up.
1 |
git rebase -i HEAD~2 |
Then, force push to GitHub by using git push origin +branchName –force
1 |
git push origin +branchName --force |