# Git Undoing changes **Undoing** in git means discarding or reverting changes. The strategy depends on whether changes are staged, committed, or already pushed. Never force-push to a shared branch; instead use `git revert` to create a new commit that undoes the old one. ```bash $ git restore # discard unstaged changes to a file $ git restore --staged # unstage a file (keep changes) $ git revert # create a new commit that undoes an old one $ git reset --soft HEAD~1 # undo the last commit, keep changes staged $ git reset --hard HEAD~1 # undo the last commit, discard changes ``` Use `git restore` for unstaged changes, `git reset` for uncommitted commits (only on your local branch), and `git revert` for pushing an undo to a shared branch. `git reset --hard` is destructive—it permanently discards changes—so use it carefully.