Git Revert

git revert can be used to revert the changes you did in your git repository. One of the most useful case would be if you have already published your commits and of course, you won’t want to do a history rewrite. Then git revert lets you make a new commit cancelling out the effect of particular commit you specify.

git log

and note down the commit id of the latest commit you want to revert. Let us assume, it’s “b338b072ex1gd89a1a4eba8ge0d56jko“.

And then:

git revert b338b072ex1gd89a1a4eba8ge0d56jko

Then do git log again and see a new commit reverting the changes of last commit. Similarly, it can be done for multiple commits to, or a range of commits.

See more options @

Video demo:


2 thoughts on “Git Revert

  1. Writing first 5 characters of hash is enough, it will work.
    If you want to revert your latest commit, you can also use git revert HEAD.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close