Bonus: Git Revert

This is a bonus exercise. We didn’t cover git revert, however it’s a powerful tool.

Git revert

git-revert - Revert some existing commits

Git revert will allow us to undo a commit.

Say for example you accidentally deleted some important directories in your local repository, you then committed the changes, and pushed them to your remote repository.

Now both your local and remote repositories are missing the files in the directories you deleted!

If only we could go back in time and undo the commit that deleted the directories.

We can with git revert.

Example Repo

Look at the history of the example repo to see this illustrated.

Commits 2 and 3 introduced two new directories with very important stuff.

Commit 4 removed the directories accidentally.

Let’s walk through the steps to revert commit 4.

Fork Example Repo

First fork the remote repo controlled by LaunchCodeTechnicalTraining to your own personal account.

Clone Example Repo

Clone your remote repository.

CLICK FOR ANSWER

Revert Commit 4

View Commit Log

CLICK FOR ANSWER

Revert Commit

Now using the commit id revert the commit. This will create a new commit that reverts the commit in question.

CLICK FOR ANSWER

Check Log for New Commit

The revert should have created a brand new commit that reverts the previous commit. The log should reflect this.

CLICK FOR ANSWER

Check Project Directory for Missing Directories

Check the contents of the revert-example directory to see that the new directories exist again.

CLICK FOR ANSWER

Push

Although we have reverted the commits on our local repo. We need to push them to update our remote repo.

CLICK FOR ANSWER