Practical guideTested1 min read
How to undo your last Git commit without losing work
If you have not pushed yet, run:
Advertisement
git reset --soft HEAD~1The commit is removed, your changes stay staged.
If you already pushed and others use the branch, do not rewrite history. Make a new commit that cancels the old one:
git revert --no-edit HEADWhich one: private branch only you use, reset --soft. Shared branch, revert. Warning: git reset --hard deletes uncommitted work, avoid it unless you are sure.
Full kit: Git Survival Kit