Discard all uncommitted changes
Wipes every uncommitted edit, staged or not, and removes untracked files too, resetting the working tree back to exactly the last commit.
Last updated
git reset --hard && git clean -fd
How it works
git reset --hard (against the implicit HEAD) throws away every staged and unstaged modification to files git already tracks, snapping them back to match the last commit exactly. It only knows about TRACKED files though, so git clean -fd runs right after to remove untracked files (-f, force — clean refuses to run without it) and untracked directories (-d) that reset --hard never touches.
Together these two commands are the standard "start completely over from the last commit" combo — reset handles what git is already tracking, clean handles everything else sitting in the working tree that git doesn't know about yet.
Watch out for
- →This is destructive and permanent from git's point of view — there is no undo command for git clean the way there sometimes is for a bad reset via the reflog; anything it removes is genuinely gone.
- →git clean -fd does NOT remove files matched by .gitignore by default (build output, node_modules, etc.) — add -x to also wipe ignored files, or run git clean -fdn first (dry run) to see exactly what would be deleted before committing to it.
- →Run this only when you're certain nothing in the working tree is worth keeping — if you're unsure, git stash first so the changes are recoverable instead of permanently discarded.