How to Discard All Local Changes in Git
Discard all unstaged and uncommitted file modifications and restore your working tree to the latest commit.
git restore .Step-by-Step Execution Guide
git restore .Reverts all modified tracked files in the current repository back to their clean commit state.
git restore --staged .Unstages all files added with "git add .", restoring them to unstaged modified status.
git clean -fdDeletes 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.
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.
Related Git Command Guides
Browse All Git RecipesUndo your most recent Git commit while keeping all your edited files staged or unstaged in your working directory.
Rename your current local branch and update the upstream remote tracking branch on GitHub or GitLab.
Delete a branch from remote origin (GitHub, GitLab, Bitbucket) after a pull request has been merged.
Amend the commit message of your latest commit before or after pushing.
Remove files from the Git staging area (index) without losing any of your local changes.
Temporarily shelve both modified and newly created untracked files to switch branches with a clean working copy.