Skip to the content.

Git: How to “undo”

-

What we’ll cover

Undoing a commit using `git revert`

Undoing a commit using `git reset`

Using `git reset` on uncommitted code

-

Undoing committed code

Reverting a commit in Git means creating a new commit that undoes the changes introduced by a previous commit. There are several ways to achieve this, depending on your specific use case. Here we’ll discuss a couple of common methods: revert and reset.

-

Undoing committed code: git revert

-

Undoing committed code: git revert

Push the changes to your remote repository if necessary:

git push <remote_alias> <branch_name>

- The git revert command is a safe way to revert changes because it creates a new commit that undoes the previous one while preserving the commit history. -

Undoing committed code: git reset

(Use with Caution!)

You can also use git reset to revert a commit, but be cautious when doing this, as it can rewrite history and potentially lose commits.

-

Undoing committed code: git reset

-

Undoing committed code: git reset

-

Undoing committed code: git reset

-

how to use git reset safely:

The safest use case git reset, is to undo changes that you haven’t yet committed to the repository.

git reset --hard

This will return your codebase to the most recent commit.

-

Recap

-