To undo the last commit but keep the changes, run the following command:
git reset --soft HEAD~1
Now when we run git status
, we will see that all of our changes are in staging. When we run git log
, we can see that our commit has been removed.
If we want to completely remove changes in staging, we can run the following command:
git reset --hard HEAD
These are dangerous commands and should be used with caution. Try it out on a different branch first. However, in the worst case scenario, we can recover commits we accidentally deleted with git reflog
.
Top comments (0)