init: git revert
In this video we'll learn how to use
There are times where you may want to undo changes in previous commit.
This could be changes that were only temporary, like a promotion or limited feature. Or simply changes that were made incorrectly.
Regardless of the reason, you can use
git revert to automatically create a new commit containing changes to undo the original commit.
Let's demonstrate this by adding a few lines to File 1.
Since this was just a quick change, I'll add and commit the changes in one step with
git commit -am which I covered in the Master video for
Now we can use
git revert to effectively undo these lines by running:
And passing the commit SHA of the commit we want to revert.
In this case, the one we just made.
git revert opens our text editor.
We see that it creates a new commit and automatically generates a commit message.
It also adds the commit SHA in the commit message body and lists the files changed in the comments.
Once we save and close the editor, Git will creates a new commit with the changes to revert the original commit.
We see this in the output and we can also check the contents of File 1 to see they were reverted.
We were able to do all of this with just one Git command.