Skip to main content

Git Discard Working Directory Changes Guide

When to Use

When you've modified files already tracked by Git but haven't run git add yet, and now want to discard these working directory changes.

This page only covers "unstaged changes to tracked files."

  • Does not handle untracked files.
  • Does not handle staged changes.
  • Does not rewrite commit history.

Check Current State First

git status --short
git diff
git diff <file>
  • git status --short -- see which files are still modified in the working directory.
  • git diff -- then decide whether these changes should indeed be discarded.
ScenarioRecommended CommandResult
Restore a single filegit restore <file>Discard unstaged changes for that file
Restore multiple filesgit restore file1 file2Batch discard unstaged changes for multiple files
Restore all tracked changes in current directorygit restore .Discard unstaged changes in current directory and subdirectories
Interactively restore partial changesgit restore -p <file>Only discard selected portions of changes

Common Scenarios

Discard Working Directory Changes for a Single File

git diff app.js
git restore app.js

Discard Working Directory Changes for Multiple Files

git restore app.js style.css index.html

Discard All Tracked Changes in Current Directory

git restore .

File Has Been Staged, Want to Undo Staging Too

git restore --staged app.js
git restore app.js

If you want to undo both staging and working directory changes at once:

git restore --source=HEAD --staged --worktree app.js

Legacy Syntax

The old syntax was typically:

git checkout -- app.js
git checkout .

These still work, but git checkout handles both "switch branch" and "restore file" -- the semantics are easy to confuse. New projects prefer git restore.

Risks and Boundaries

  • These commands only affect unstaged changes to tracked files.
  • Untracked files won't be deleted; to clean them, see Clean Untracked Files.
  • Staged changes won't be cancelled by the basic commands on this page; to undo git add, see Undo git add.
  • If you're not sure whether to discard yet, using git stash first is safer.
git status --short
git restore --staged <file>
git clean -nd
git stash push -u -m "wip"