There are situations where you just committed a change in git and just after that realized you made a mistake in the last commit. If you haven’t pushed that code then the last local changes can be undone with the following command.
git reset --soft HEAD~1
What this does is that it uncommits the last change and puts that back in a staged state. That means if you run the
git status command then you will see those changes in your working directory. Now you can make further changes to that revision and then commit again.