Bonus: Git Revert
This is a bonus exercise. We didn’t cover
git revert, however it’s a powerful tool.
git-revert - Revert some existing commits
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
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.
Revert Commit 4
View Commit Log
Now using the commit id revert the commit. This will create a new commit that reverts the commit in question.
Check Log for New Commit
The revert should have created a brand new commit that reverts the previous commit. The log should reflect this.
Check Project Directory for Missing Directories
Check the contents of the
revert-example directory to see that the new directories exist again.
Although we have reverted the commits on our local repo. We need to push them to update our remote repo.