Throw away changes to one file with git restore
Made a mess of one file? Put it back the way it was at your last commit or git add, without touching anything else.
- Run
git statusto see which file you've changed. - Run
git restore <file>to discard your edits to it. - Staged it already? Run
git restore --staged <file>first to unstage it, then restore.
Tip: Restored edits are gone, not stashed. If you might want them back, use git stash instead.
Try it now: Add a junk line to a tracked file, run
git diff, then git restore the file and run git diff again: it's empty.Next crumbs
- 💻 Terminal & gitPark unfinished work with git stashNeed to switch branches but you're mid-change? Stash it, switch, and bring it back later.
- 💻 Terminal & gitFix your last commit with --amendForgot a file or made a typo in the message? Fold the fix into the commit you just made.
- 💻 Terminal & gitJump back with cd -Toggle between your last two directories, like Alt+Tab for folders.