Summary of Git Undo Operations: Differences Between reset, revert, and restore

Git provides three undo tools, reset, revert, and restore, which are similar in function but differ greatly in scenario and should be chosen accordingly: **git reset**: adjusts branch pointers and discards some commits. Three modes: --mixed (default, rolls back the pointer and staging area while keeping the working directory), --soft (rolls back only the pointer, keeping changes), and --hard (complete rollback, the most dangerous). Suitable for quick local rollbacks of unpushed commits; never use --hard on pushed branches. **git revert**: creates a new commit that reverses changes while preserving the original history. Simple syntax (e.g. git revert HEAD~1) safely rolls back pushed branches without damaging team history. **git restore**: precisely restores files without affecting branches. It can unstage (git restore --staged <file>) or restore a single file to a historical version (git restore --source=HEAD~1 <file>), replacing the old git checkout -- with clearer semantics. **Differences**: reset adjusts branch pointers (dangerous), revert adds an undo commit (safe), and restore restores single files (precise). Decision rule: for local unpushed commits use ...

Read More