Rajanand Ilangovan
Rajanand Ilangovan

Rajanand Ilangovan

How to undo the last git commit in local repository?

Rajanand Ilangovan's photo
Rajanand Ilangovan
·Jul 28, 2022·

1 min read

Undo last local commit but keep files changes.

git reset HEAD~1
  • All the changes committed in the last commit is present in the local repo.
  • Changes are not present in stage.

Undo last local commit and keep files changes in stage.

git reset --soft HEAD~1
  • No need to do git add again to add the changes to stage.

Undo last local commit and remove the changes from the repository.

git reset --hard HEAD~1
  • Git commit has been reversed.
  • The changes also removed from the local repository.
  • This option can be used before start using the branch. Just to make sure the branch is clean before making changes.

Impressum