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
Code language: HTML, XML (xml)

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
Code language: HTML, XML (xml)

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

Better luck next time!

Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments