Git Revert Commit

September 23, 2016

Git Revert Commit

At one point or another you are going to make a commit that you will regret afterward. Maybe it is a bad merge. Or maybe it is some animation that just brakes half of your screen layout at the end yet you notice it two days later, as well as 10 commits later.
But what if I told you you can revert that commit?

<!--more-->

Imagine you have a commit you wish to revert. On the screenshot you see a commit to which HEAD is pointing. We want to revert that one.

Git Revert Commit

Git has a simple command that is going to try to revert changes you made and then make a new commit. All you have to do is provide the number of the commit if you count away from the HEAD, which means if you want to discard commit your HEAD is currently pointing to - do it like this:

git revert HEAD

Similarly, in case you want to revert commit before the last one, then that one is going to have a number 1 if to count away from the current and it is going to look like this:

git revert HEAD~1

As a result we will see a new commit that has reverted the changes from the commit we have specified.

Git Revert Commit

In case you are lucky then you will have no merge conflicts to deal with.

Comments

comments powered by Disqus