Git revert
For many developers, there is no bigger nightmare than having changes that have been committed to the production stage causing system failures.
The best preventative action is to ensure extensive testing of any changes before the production stage. Automated tests are essential tools to help ensure that a commit won’t ‘break’ production.
Let’s not be naive though, humans are prone to mistakes, consequently it is likely that a commit still ends up breaking production.
Git revert
involves undoing the specific changes introduced by the commit, effectively bringing the codebase back to its previous stable state. This approach is a reverse git cherry-pick
, as it creates a new commit that applies the exact opposite of the change introduced, essentially undoing it.
Reverting to most recent commit
Even seasoned developers, still forget (just like myself) how to revert commits. Here are the steps to follow:
Note: glog is an alias ‘git log — oneline — decorate — graph’ in my .zshrc




Now let’s fix the bug. Git revert
requires the id of the commit you want to remove and keep in your history.

After selecting the commit id, git
will prepend the word Revert to the original commit message. :wq!
to save changes.

After applying the changes, run git log
to verify whether the reverted commited has been added.

Let’s test the application after the revert.

Last but not least, don’t forget to push.
