skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
git-undoing
This page is read only. You can view the source, but not change it.
# 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 <file> # discard unstaged changes to a file $ git restore --staged <file> # unstage a file (keep changes) $ git revert <hash> # 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.
Page Tools
Show pagesource
Backlinks
Back to top