Revert those changes in Git

Git Nov 23, 2021

Continuing on the theme of Git commands you should know.  Today I am looking at using git to revert that last commit.

Occasionally you'll want to  undo the changes you've just made.  And there are various ways to do that either locally or remotely depending on what you need, but you do have to be careful when doing that and avoid unwanted deletions.

The way I prefer to do this is using git revert.  

Look at the logs

The first thing to do is look back at your logs and find the commit details using the command git log --oneline

Git Log

Revert the change

We want the hash number that is next to your latest commits. That little number helps us revert the change we want to make.

One we have a note of that number we want to issue the command git revert 7270d13

You'll be taken into a screen where you can make edits. You should be able to exit using :wq

You'll exit the editor and be taken back to your command line where you'll see that the commit that you reverted has been reverted.

Git Revert Confirm

If you now run git log --oneline you'll see a new commit has been created to carry out that revert.

Let me know your favourite way to revert a change within Git.

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.