Skills › 💻 Terminal & git

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.

⏱ 20s

  1. Run git status to see which file you've changed.
  2. Run git restore <file> to discard your edits to it.
  3. 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.

Practice in the feed →

Next crumbs

Sources