Think Like a Git, Commit Like a Boss: Revert Now!

The “revert” feature solves a different problem: You might have one particular commit that you want to undo – but you don’t want to touch any other commits that came after it.

Revert solves this problem by creating a new commit that contains opposite changes – essentially reverting the effect of those changes. E.g. if you deleted some lines in a certain commit, reverting it will create a new commit that adds exactly these lines back.

Now for our project git-education:

Let’s revert our last commit like so:

Note: eb945247d758529843bc25ffa347d794707d4111 refers to the commit hash of the most recent commit in the git history.

Now, go ahead and check the notes.txt file, You’ll discover it removes the last change. Now run git log to check the history:

Dang!!, the history still remains unchanged!. So the difference between Reset and Revert is this:

1.Revert doesn’t change the project history, which makes it safe for commits that have already been published to a shared repository. Reset alters the history.

2. Revert only undo changes in a particular commit that was referenced at any point in the git history. Meanwhile, Reset removes all the commit that occurred after the commit that is been referenced currently.

So, when you are working on a project with other developers. It’s always advisable not to alter the git history at all. You will be considered Evil if you delete the history at any point unless it’s absolutely necessary. The git history is always necessary to track down the activities of several developers on a project and also easily track down the time a bug was introduced into the project.

Please, Let me know if you have any questions in the comment section. Stay tuned for More! :smile:





Food Ninja, Code Slinger, Technical Trainer, Accidental Writer, Open Source Advocate and Developer Evangelist.