Andrew Lee
Posted on April 30, 2020
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
.
💖 💪 🙅 🚩
Andrew Lee
Posted on April 30, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
career How to Improve Our GitHub? How to Prepare a Profile? How to Write a README?
November 29, 2024