How To Undo Last Git Commit
2 min readMay 28, 2022
There are times you mess up the committed code and realize it’s not working. So instead of pushing it to the master repository, you want to go back to the previous commit, change the errors, and commit correct version. This happens quite a lot!
The key here is that you committed the code but didn’t push it yet.
Sometimes the fastest way to learn is to watch!
This is probably one of the best video tutorials on the subject.
Below are the two key commands you should use.
Should I do a Hard or a Soft reset?
This depends on whether you want to keep the erroneous changes (so you can adjust them and re-commit again) or get rid of the changes completely and go back to the state of code as seen in previous commit.