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
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
2.4 Git Basics - 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...
Discussions

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
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
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
Why doesn’t git reset --hard HEAD remove untracked files?
untracked.txt is "not in the way of writing any tracked files" therefore does not get touched. An example of where this would matter is if you had "untracked.txt" committed in an older commit, deleted it in a newer commit, recreated it in the working tree, and then reset to the older commit. If you want to purge out everything except what is held in tracked files, then you want Git - git-clean Documentation More on reddit.com
🌐 r/git
17
6
January 8, 2025
🌐
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
6 days ago - Discard uncommitted changes with git restore. Covers discarding working directory changes, unstaging files, and restoring from specific commits.
🌐
Graphite
graphite.com › guides › git-discard-changes
How to discard changes in Git - Graphite
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:
🌐
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.

🌐
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.
🌐
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.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-discard-all-changes-in-git
How to Discard all Changes in Git? - GeeksforGeeks
July 23, 2025 - Note: Here we can observe that after staging ex.py using git add command using git reset HEAD ex.py the file goes back to unstaged state and is shown using U next to file name. Make sure to use these commands with caution, as they will discard ...
🌐
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-discard-changes-in-git
How to Discard Changes in Git? - GeeksforGeeks
July 23, 2025 - In Git, "discard changes" refers to reverting modifications made to files in your working directory back to their state in the last commit, effectively disregarding any changes you've made since then.
🌐
30 Seconds of Code
30secondsofcode.org › home › git › branch › discard changes
Discard uncommitted or untracked changes in Git - 30 seconds of code
April 12, 2024 - This command will reset your working directory to match the latest commit on the current branch, discarding all uncommitted changes. ... Be careful when using git reset --hard HEAD, as it is a potentially destructive action.
🌐
Graphite
graphite.com › guides › how-to-discard-local-changes-in-git
How to discard local changes in Git - Graphite
To switch branches and discard local changes related to the current branch, you can run: ... Here, <branch_name> is the name of the branch you want to switch to. The -f flag forces Git to discard local changes, allowing you to switch branches ...
🌐
DEV Community
dev.to › cicube › how-to-discard-local-changes-in-git-43na
How to Discard Local Changes in Git - DEV Community
November 6, 2024 - If you want to discard all changes ... files. Starting with Git version 2.23, there is a more intuitive way using the command git restore....
🌐
GoLinuxCloud
golinuxcloud.com › home › devops › git › git discard changes explained (undo, remove, reset all changes with examples)
Git Discard Changes Explained (Undo, Remove, Reset All Changes with Examples) | GoLinuxCloud
March 20, 2026 - Learn how to discard changes in Git with practical examples. This guide covers how to undo local changes, remove unstaged and staged changes, reset commits, and safely discard all changes using git restore, reset, clean, stash, and revert commands.
🌐
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.
🌐
CICube
cicube.io › blog › discard-local-changes-in-git
Git Discard Local Changes | CICube
February 4, 2025 - Unstage all changes but keep them in working directory · git reset HEAD # Unstage specific file git reset HEAD <file> # Unstage and discard changes (be careful!) git reset --hard HEAD
🌐
DevQA
devqa.io › git-discard-local-changes
How to Discard Your Local Changes in Git: An Illustrated Guide
July 19, 2023 - Now, run the following command: ... staged (i.e., changes that are still in your working directory), you can use the git checkout command....
🌐
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.
🌐
GitHowTo
githowto.com › undoing_local_changes
12. Discarding local changes (before staging)
$ git status On branch 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: hello.html no changes added to commit (use "git add" and/or "git commit -a")