How to delete/revert a Git commit

0 min read 123 words

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!

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags