Loading Depth Study
Preparing your workspace
Git provides different tools for undoing working changes, creating reversal commits, moving branch history, and temporarily storing unfinished work.
git restore can discard or restore working-tree changes. git revert creates a new commit that reverses an earlier commit and is generally safer for already-shared history. git reset moves a branch reference and can rewrite local history, so it should be used carefully on shared branches. git stash temporarily stores uncommitted changes so you can switch tasks. Tools such as reflog can help recover references after certain accidental operations.
A developer can stash unfinished work, switch to fix an urgent bug, commit the fix, and later restore the stashed changes.
git stash push -m "WIP dashboard" git switch main # Fix and commit urgent work git switch feature/dashboard git stash pop
Unfinished dashboard work is temporarily stored, another task is completed, and the previous changes are restored later.