git restore . discards every tracked edit; add git clean -fd to also delete new untracked files. Both are irreversible, so run git status first and be sure.Guide
The gentlest undos: throw away edits you haven't committed, or pull a file back out of staging.
You changed some files and you regret it. Nothing is committed yet — which makes this the easiest kind of undo, because there's no history to rewrite. The only question that matters is where the change currently lives, because that picks the tool:
git add → discard it with git restore.git add (see Add & Commit) → pull it back out with git restore --staged.git clean.Not sure which bucket you're in? git status tells you, file by file.
Escape hatch: only mostly sure you want the work gone? Don't discard — stash. git stash shelves the changes where you can get them back later. See Stashing Changes.
You edited a file and want to throw those changes away, back to the last commit. That's
git restore. (This permanently drops uncommitted edits — there's no undo for the undo here.)
Throw away working-tree changes
$ git restore src/app.js # one file
$ git restore . # every changed file Older tutorials use 'git checkout -- file' for this. git restore is the modern, clearer name.
You ran git add too eagerly. git restore --staged moves a file back
out of the staging area without touching your actual edits — the file on disk stays exactly
as you left it; it just won't be part of the next commit.
Take a file back out of the next commit
$ git restore --staged src/app.js
$ # your edits are still there, just no longer staged
New files Git isn't tracking yet won't go away with restore — Git has no earlier
version to restore them to. git clean deletes them. Always dry-run with
-n first to see what would go.
Delete untracked files and folders
$ git clean -n # dry run: list what WOULD be deleted
$ git clean -fd # actually delete files (-f) and folders (-d) -f is required because clean permanently deletes — there's no recycle bin.
Tip: when VS Code's Discard Changes hits an untracked file, it doesn't delete it outright — it moves the file to your operating system's Recycle Bin (Trash on a Mac), so a hasty click is recoverable. Terminal git clean gives you no such cushion.
Warning: git restore and git clean are the two undos with no undo. They delete work that was never committed, so not even Git's safety net (reflog, covered in Undo Commits) can bring it back. Read the filename twice before pressing Enter.
Quick map: discard edits → restore · unstage → restore --staged · delete untracked files → clean (dry-run with -n first).
Up next: that covers changes you never committed. When the mistake is already in a commit, you need the bigger tools — amend, reset, revert and reflog — in Undo Commits.
FAQ
git restore . discards every tracked edit; add git clean -fd to also delete new untracked files. Both are irreversible, so run git status first and be sure.git restore path/to/file — only that file snaps back to its last committed version. In VS Code, hover the file in the Source Control panel and click Discard Changes.git restore) deletes your edits for good. Unstaging (git restore --staged) only pulls a file back out of the next commit — the edits stay in the file, untouched.git clean offers no such cushion.