To discard unstaged changes in Git, use git restore . (Git 2.23+) or the older git checkout -- . to revert your working directory back to the last committed state. This is a common cleanup step when you’ve made edits you no longer want to keep, and it’s fast and safe as long as you check what you’re about to lose first.
Quick Command
For most cases, this is all you need:
git restore .
This discards unstaged changes across your entire working directory, restoring every modified tracked file to its last committed version.
Discard Changes in a Specific File
If you only want to revert one file rather than everything:
git restore path/to/file
Or with the older syntax:
git checkout -- path/to/file
Older Git Versions
If you’re on a Git version older than 2.23 (or just used to the older syntax), git checkout still works the same way:
git checkout -- .
The -- tells Git you’re referring to a path, not a branch name, which avoids ambiguity.
Check What Will Be Discarded First
Before running any discard command, it’s worth reviewing what’s about to be lost:
git status
git diff
git status lists modified and untracked files, while git diff shows the exact line-by-line changes. Once you run a restore or checkout command, those unstaged edits are gone for good — there’s no undo.
Discarding Untracked Files Too
git restore and git checkout only affect tracked files that Git already knows about. If you also have new, untracked files (like a file you created but never git added) that you want to remove, use git clean instead:
git clean -fd
-f forces the removal (required by default as a safety measure)
-d also removes untracked directories
Add -x if you also want to remove files ignored by .gitignore:
git clean -fdx
Be careful with git clean — unlike a stash, there’s no way to recover deleted untracked files afterward.
If You’re Not Sure Yet — Stash Instead
If you’re not ready to permanently discard changes but want a clean working directory temporarily (for example, to switch branches), stash them instead:
git stash
This saves your changes and reverts your working directory to the last commit. You can bring them back later with:
git stash pop
Nuclear Option: Reset Everything
If you want to wipe out both staged and unstaged changes in one step, use:
git reset --hard HEAD
This resets your entire working directory and staging area to match the last commit. It’s more aggressive than git restore ., since it also clears anything you’ve already staged with git add. Use with caution — this is irreversible.
Common Mistakes to Avoid
- Running a discard command without checking
git status first. Once changes are discarded, they can’t be recovered unless you stashed or backed them up beforehand.
- Confusing
git restore with git restore --staged. The latter unstages files without discarding their changes — it’s a different operation entirely.
- Forgetting that discard commands don’t touch untracked files. If you expect a file to disappear and it doesn’t, it’s likely untracked and needs
git clean instead.
- Using
git reset --hard when you only meant to discard unstaged changes. This also removes anything staged with git add, which may not be what you intended.
Join The Discussion
Discarding changes safely is one of those Git habits that becomes second nature once you’ve been burned by an accidental loss. What’s your go-to command for cleaning up a working directory — git restore, the older git checkout --, or do you always stash first as a safety net? Share your workflow, any close calls you’ve had, or tips for avoiding accidental data loss when working across branches.