Undo & History

How to Discard All Local Changes in Git

Discard all unstaged and uncommitted file modifications and restore your working tree to the latest commit.

Instant 1-Line Solution
Destructive (Data Loss Risk)Beginner
git restore .
When to use this scenario:You experimented with code that didn't work out and want to cleanly discard all changes since your last commit.

Step-by-Step Execution Guide

1Discard unstaged changes in all tracked files
git restore .

Reverts all modified tracked files in the current repository back to their clean commit state.

2Discard staged files
git restore --staged .

Unstages all files added with "git add .", restoring them to unstaged modified status.

3Remove untracked files and directories
git clean -fd

Deletes any new untracked files (-f) and untracked directories (-d) created during your experiments.

Critical Pitfalls & Precautions

  • β€’"git restore ." and "git clean -fd" cannot be undone! Once discarded, unstaged work is permanently erased.
  • β€’Consider running "git stash" instead if you might need these experiments later.
Frequently Asked Questions

Discard All Local Changes - Frequently Asked Questions

Common questions about safe rollback, remote history implications, and troubleshooting.

Git 2.23+ introduced "git restore .", which is the recommended, safer syntax for discarding working tree modifications.