DEV Community

Cover image for Revert those changes in Git
Sarah Lean 🏴󠁧󠁒
Sarah Lean 🏴󠁧󠁒

Posted on β€’ Originally published at techielass.com

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

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.

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

Git Revert Confirm

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

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay