Revert those changes in Git

Sarah Lean
2 min readJan 6, 2022
Revert those changes in Git

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

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.

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.

--

--

Sarah Lean
Sarah Lean

Written by Sarah Lean

Community Speaker — Lifelong Learner — Founder of the Glasgow Azure User Group

No responses yet