For all unstaged files in current working directory use:

git restore .

For a specific file use:

git restore path/to/file/to/revert

That together with git switch replaces the overloaded git checkout (see here), and thus removes the argument disambiguation.

If a file has both staged and unstaged changes, only the unstaged changes shown in git diff are reverted. Changes shown in git diff --staged stay intact.

Before Git 2.23

For all unstaged files in current working directory:

git checkout -- .

For a specific file:

git checkout -- path/to/file/to/revert

-- here to remove ambiguity (this is known as argument disambiguation).

Answer from Tobi on Stack Overflow
🌐
Reddit
reddit.com › r/git › how to discard all changes so i can switch branch
r/git on Reddit: How to discard all changes so I can switch branch
October 3, 2019 -

I was trying to clean up git and use it in a better way, but the master is now so far from the branch I am working on, I will have to do it another way. The issue I am having is that I have made a couple of small changes just to get the site working locally to find that it is too far gone.

The issue now is git won't let me switch to a different branch without committing and I desparately do not under any circumstances want to do that. How can I just get rid of the changes, I don't need to stash them, I just need to get back to my work. In the past I have just had to delete the folder from my computer and clone it again from github, but there must be a way to just ignore the changes and checkout another branch. Any help would be appreciated I'm panicking currently and worried I'm about to lose 5 months of work because of git when I'm trying to learn how to use it.

I've tried:

git reset --hard HEAD

but that doesn't work

UPDATE: Thank you to all who responded to my post and apologies for lack of response, I have been on Annual Leave.

The upshot of all of this is that I need to learn git a lot better, so am just doing a course on linkedIn Learning so I don't get into this mess again. And for the record it just covered what I think I should have done:

"git log" - to find the last commit and copy SHA

"checkout -- SHA" - this lets git take you back to same status as last commit and reverts all unstaged changes.

There may well be a better or quicker way to do this, but this does it perfectly. And on a side note the course introduced me to the concept of atomic commits as a good practice.

Discussions

How do you discard changes in one file?
How do I do the equivalent of git reset foo/bar/ or git checkout foo/bar/ so I can throw away changes on that file/dir only? I've seen the d and D options but they all seem to apply to the whole directory, not just a path. ... If you want to discard just a specific file, move the cursor to the file. More on github.com
🌐 github.com
1
4
How do I discard unstaged changes in Git? - Ask a Question - TestMu AI (formerly LambdaTest) Community
How do I discard unstaged changes in Git More on community.testmuai.com
🌐 community.testmuai.com
0
June 28, 2024
How to discard all changes so I can switch branch
I've tried: git reset --hard HEAD but that doesn't work What does it do, that isn't "work"? More on reddit.com
🌐 r/git
15
3
October 3, 2019
Discard all changes made to a file in a branch
You can use git checkout -- path/from/repo/root/to/yarn.lock . For example, if yarn.lock is in the root of your repo and you want to restore it to the commit beginning with 123abc, you can git checkout 123abc -- yarn.lock then when you commit the file, it should be in the same state it was as of commit 123abc. Note that the diff won't show the changes (when they hit "compare"), but the history will show whatever intermediate states the file went through unless you're doing something that rewrites the history, such as rebasing or squashing. More on reddit.com
🌐 r/git
27
8
May 9, 2021
🌐
GitLab
docs.gitlab.com › topics › git › undo
Revert and undo changes | GitLab Docs
You can modify history by using git rebase -i. Use this command to modify, squash, and delete commits. # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # d, drop = remove commit # # These lines can be re-ordered; they are executed from top to bottom.
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
Git - Undoing Things
$ git reset HEAD CONTRIBUTING.md ... -> README Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: CONTRIBUTING.md...
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › remove-revert-discard-local-uncommitted-changes-Git-how-to
How to discard local changes in Git
The git stash command, which saves uncommitted changes and reset your workspace. The git reset command, which only touches tracked files. The git clean command, that deletes every untracked file.
🌐
Git Tower
git-tower.com › learn › git faq › how to discard changes in git with git restore
How to Discard Changes in Git with git restore | Learn Version Control with Git
4 days ago - Discard uncommitted changes with git restore. Covers discarding working directory changes, unstaging files, and restoring from specific commits.
Find elsewhere
🌐
JanBask Training
janbasktraining.com › community › devops › how-do-i-discard-unstaged-changes-in-git
How do I discard unstaged changes in Git? | JanBask Training Community
August 26, 2025 - This temporarily saves your changes without committing them. ... Use git restore (or git checkout -- in older versions) to discard unstaged changes safely.
🌐
Graphite
graphite.com › guides › git-discard-changes
How to discard changes in Git
Discard all changes in the working directory: If you want to discard changes from all files in the working directory: ... This will revert all of your tracked files back to the state they were in at the last commit. However, this will not affect "untracked" files, new files that have been created locally but not committed yet, or other files that are auto-generated and shouldn't be committed to the repository like build artifacts, compiled binaries, log files etc. Git 2.23 introduced a more straightforward command called git restore, designed to make it easier to work with changes:
🌐
Tempertemper
tempertemper.net › blog › git-restore-to-discard-changes
Git restore to discard changes – tempertemper
throw out all of your changes, regardless of filetype or directory using git restore . (actually, you can do that with git checkout --, but I like that the . follows the same pattern as git add) discard changes to staged files by using the --staged ...
🌐
Debugging Guide
uchicago-cs.github.io › student-resource-guide › tutorials › git-discarding-changes.html
Git Tutorial - Discarding Changes and Unstaging — UChicago CS Student Resource Guide
On branch main Your branch is up to date with 'origin/main'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: README.md no changes added to commit (use "git add" and/or "git ...
🌐
Medium
medium.com › @haroldfinch01 › how-do-i-discard-unstaged-changes-in-git-ff77fbcfed72
How Do I Discard Unstaged Changes in Git | by Harold Finch | Medium
September 10, 2025 - Best practice favors git restore for clarity and to avoid accidental branch switching. Discarding is irreversible. Once executed, the modifications are permanently lost. To safeguard work · Use stashing: Save changes temporarily with git stash before discarding.
🌐
DEV Community
dev.to › reiyszw › discard-file-changes-by-vscode-instead-of-git-stash-47h6
Discard File Changes by VSCode Instead of git stash - DEV Community
June 25, 2020 - Lately, I have found a much simple solution to discard file changes. Everyone should use that. ... That's it! If you have specific files to discard, You only need to select that file. I'm not familiar with this type of superpower of VSCode. If you know about VSCode tips to improve productivity, Please let me know. I would really appreciate it. Thanks! ... git restore --staged pathToFileOrFolder # first unstage file git checkout pathToFileOrFolder # then revert changes
🌐
GitHub
gist.github.com › ec5ff3bf7a4df94f38ee
GIT - Discard all local changes and pull · GitHub
GIT - Discard all local changes and pull. GitHub Gist: instantly share code, notes, and snippets.
🌐
Better Stack
betterstack.com › community › questions › git-unfo-all-uncommet-or-unsaved-changes
Git Undo All Uncommitted or Unsaved Changes | Better Stack Community
Unstage Changes: git restore --staged . or git reset · Discard Both Staged and Unstaged Changes: git reset --hard HEAD
🌐
KAY SINGH
singhkays.com › blogs › how do i discard unstaged changes in git?
How do I discard unstaged changes in Git? | KAY SINGH
May 22, 2026 - I knew I would be working on device 1 the next day and would not be able to pull in remote changes without causing merge conflicts. I use Visual Studio Code for editing the markdown. VS Code places a whole set of git operations just a click away. Discard is one of them as shown in the image below
🌐
JanBask Training
janbasktraining.com › community › devops › how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state
How do I revert all local changes in Git managed project to previous state? | JanBask Training Community
August 18, 2025 - Always double-check with git status before running cleanup commands. In short, you can revert all local changes by combining git reset --hard and git clean -fd.
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › devops › repos › git › undo
Undo changes in your Git repo - Azure Repos | Microsoft Learn
If the file is in the Changes section, right-click it and choose Undo Changes to discard all changes to the file since the last commit. Visual Studio 2019 provides a Git version control experience by using the Git menu, Git Changes, and through ...
🌐
JetBrains
jetbrains.com › help › idea › undo-changes.html
Undo changes in Git repository | IntelliJ IDEA Documentation
May 5, 2026 - If you have committed changes in ... dropped changes will be deleted. In the Log tab of the Git tool window Alt+9, select the local branch and then the commit with the changes you want to drop....