How to Delete/Revert a Git Commit


You’ve just pushed something to a Git repository and you immediately regret it!

Run git log to see what the commit id was:

git log

Take the first 7 characters of the commit SHA id and do the following:

git revert <commit_id>
git push --force

But if you’re like me and your problem was because of a merge conflict that you tried to resolve and clearly failed at, but still had the balls to push to the repo before wishing you hadn’t; you can still recover this terrible moment in your life by undoing the merge request itself.

git revert <commit_id> -m 1
git push

This will allow you to literally undo the merge that you previously failed at!

Better luck next time!