Getting Git

A comprehensive video course from git init to Git Master.

Master: git revert

In this video we'll Master git revert

The init video covered how to use git revert to undo all changes in a previous commit.

Sometimes the revert process is not so simple.

For example, maybe you want to undo only some of the changes or want to undo the commit as well as add some changes.

In these situations, you can use the -n option, which stands for no commit

Let's demonstrate this by adding a few lines to File 1 and committing those changes.

Now we can take this commit SHA and use it to run:

git revert -n

and pass the SHA.

If we run git status we see we are now in a state of reverting.

You'll also notice that my command prompt showed this state.

We now have the opportunity to use git add or git remove to stage the changes we want to undo as well as add more.

When you're ready, you can run:

git revert --continue

to complete the revert. In these situations, I like adjust the commit message to highlight my additional changes. This way when I, or someone else, looks back at the commit history they won't think it's just an automatic revert.

Taking a step back, if at anytime you wanted to abandon the revert, you could run:

git revert --abort

Doing so will reset the current state back to its previously clean state.