On This Page
How to Discard Local Uncommitted Changes in Git
Quick Answer: To discard uncommitted modifications in a specific file, run git restore <file>. To discard all modifications in tracked files across the entire project, run git restore .. To remove untracked files and folders, run git clean -fd. To wipe out all changes (staged, unstaged, and untracked), run git reset --hard && git clean -fd.
Quick Reference Cheat Sheet
| Situation | Command | Safe / Destructive |
|---|---|---|
| Discard edits in 1 tracked file | git restore <file> | ⚠️ Destructive for file edits |
| Discard all tracked file edits | git restore . | ⚠️ Destructive for file edits |
| Unstage a file (keep edits) | git restore --staged <file> | ✅ Safe |
| Delete all untracked files/folders | git clean -fd | ⚠️ Permanently deletes files |
| Preview untracked files to delete | git clean -nd | ✅ Dry-run preview |
| Nuke all changes & untracked files | git reset --hard && git clean -fd | ⚠️ Wipes everything uncommitted |
1. Discarding Modifications in Tracked Files
Discard edits in a single file
$ git restore src/app.js
Discard all modified tracked files in the workspace
$ git restore .
Git < 2.23 alternative: Before Git 2.23 introduced
git restore, developers usedgit checkout -- .to achieve the same result.
2. Unstaging Staged Changes (Without Losing Edits)
If you ran git add . and want to unstage files while keeping your code edits intact:
# Unstage a single file
$ git restore --staged package.json
# Unstage all files
$ git restore --staged .
For more details on how staging works, read /git-add and /git-status.
3. Removing Untracked Files and Directories (git clean)
Files that have never been added to Git are untracked. git restore does not delete untracked files. Use git clean:
# 1. Always run a dry run first to see what will be deleted
$ git clean -nd
# 2. Force delete untracked files and directories (-f = force, -d = directories)
$ git clean -fd
To also remove ignored files (e.g. node_modules/ or build output):
$ git clean -xfd
4. Temporary Saving Instead of Discarding (git stash)
If you aren’t sure whether you’ll need your local changes later, don’t discard them permanently. Stash them instead:
# Save uncommitted changes to temporary storage
$ git stash -u
# Restore them later whenever you're ready
$ git stash pop
Learn more in our guide on /git-stash.