KKAIROSافتح التطبيق
Practical guideTested1 min read

How to undo your last Git commit without losing work

If you have not pushed yet, run:

Published:

Advertisement
Before and after: git reset --soft HEAD~1 A B C HEAD commit removed Your work stays staged
Before and after: git reset --soft HEAD~1
git reset --soft HEAD~1

The 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 HEAD

Which 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