Deshacer cambios
Recupérate de los errores: reset, revert y deshaz commits de forma segura.
How to undo things in Git
Almost nothing in Git is truly lost, but the right undo depends on where the mistake lives. Uncommitted changes can be stashed or discarded; a local commit can be reset away as if it never happened; a pushed commit should be reverted - a new commit that reverses it - so shared history is never rewritten.
The pages in this category walk through each case: git reset and its --soft/--mixed/--hard modes, git revert for published history, git stash for work you want back later, and git reflog - the safety net that can recover commits even after a hard reset.
Preguntas frecuentes
How do I undo my last commit but keep the changes?
git reset --soft HEAD~1 removes the commit and leaves everything staged, ready to re-commit. Use git reset HEAD~1 (mixed) to also unstage, or git reset --hard HEAD~1 to discard the changes entirely.What is the difference between git reset and git revert?
git reset moves your branch pointer back, erasing commits from the branch - right for local, unpushed mistakes. git revert adds a new commit that undoes an earlier one, keeping history intact - the safe choice for anything already pushed.Can I recover commits after git reset --hard?
git reflog lists every commit HEAD has pointed at, including the ones you just reset away. Find the lost commit hash in the list and restore it with git reset --hard <hash> or git cherry-pick <hash>.