Discard & Unstage Changes

The situation

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:

  • In your working folder — you edited a file but haven't run git add → discard it with git restore.
  • In the staging area — you already ran git add (see Add & Commit) → pull it back out with git restore --staged.
  • A brand-new file Git has never tracked → delete it with 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.

Discard edits to a file

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

Terminal
$ git restore src/app.js   # one file
$ git restore .             # every changed file
In VS Code
  1. Source Control panel → hover the file → ↩ Discard Changes
  2. VS Code asks to confirm, since this can't be undone

Older tutorials use 'git checkout -- file' for this. git restore is the modern, clearer name.

Unstage, keep the edits

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

Terminal
$ git restore --staged src/app.js
$ # your edits are still there, just no longer staged
In VS Code
  1. Source Control panel → hover the staged file → − (Unstage Changes)

Delete brand-new untracked files

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

Terminal
$ git clean -n        # dry run: list what WOULD be deleted
$ git clean -fd       # actually delete files (-f) and folders (-d)
In VS Code
  1. Source Control → '…' → Discard All Changes can also remove untracked files
  2. When unsure, run the -n dry run in the terminal first

-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

Frequently Asked Questions

How do I discard all my uncommitted changes?
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.
How do I discard changes to just one file?
Run 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.
What's the difference between discarding and unstaging?
Discarding (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.
VS Code's Discard Changes removed a new file — where did it go?
For untracked files, VS Code moves the file to your operating system's Recycle Bin (Trash on a Mac) instead of deleting it, so you can restore it from there. Terminal git clean offers no such cushion.