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.
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.
For an easy revert if it's just a mistake (perhaps you forked a repo, then ended up pushing to the original instead of to a new one) here's another possibility:
Obviously swap in that number for the number of the commit you want to return to.
Everything since then will be deleted once you push again. To do that, the next step would be:
If you are doing this because you have sensitive data in a commit, using the other answers here is not safe (excepting subutux's, which I'll expand on).
The github guide on this recommends using a external tool, but I prefer using the built-in one.
Firstly, make a backup of your repository. Then:
After this, make sure the repository is in the state you want. You might want to diff against the backup.
If you're sure it's correct, then:
You might want to keep the local backup for a while, just in case.
if you want to remove do interactive rebase,
git rebase -i HEAD~4
4 represents total number of commits to display count your commit and
change it accordinglyand delete commit you want from list...
save changes by Ctrl+X(ubuntu) or :wq(centos)
2nd method, do revert,
this will revert specific commit