To revert changes made to your working copy, do this:

git checkout .

Or equivalently, for git version >= 2.23:

git restore .

To revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:

git reset

To revert a change that you have committed:

git revert <commit 1> <commit 2>

To remove untracked files (e.g., new files, generated files):

git clean -f

Or untracked directories (e.g., new or automatically generated directories):

git clean -fd
Answer from 1800 INFORMATION on Stack Overflow
🌐
GitLab
docs.gitlab.com › topics › git › undo
Revert and undo changes | GitLab Docs
When you stage a file in Git, you instruct Git to track changes to the file in preparation for a commit. To disregard changes to a file, and not include it in your next commit, unstage the file. ... On branch main Your branch is up-to-date with 'origin/main'.
Discussions

Reset all local changes - Sublime Merge - Sublime Forum
Is there a way to delete all local changes and reset back to whatever the most current version is? I’ve done some research, and either there’s nothing on this or I’m just using the wrong words to search. Basically, I just want to get rid of any local changes (I don’t care about them) ... More on forum.sublimetext.com
🌐 forum.sublimetext.com
May 7, 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
Is there a way to remove all local commits while keeping the changes?
You can git reset --soft to the last commit you want to keep: https://git-scm.com/docs/git-reset More on reddit.com
🌐 r/git
27
5
February 17, 2022
🌐
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 easiest way to restore your working directory and discard any local changes is to issue a git stash command. This not only discards all local changes, but it also stores a record of your changes for future retrieval with a pop or apply command.
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
Git - Undoing Things
$ git reset HEAD CONTRIBUTING.md Unstaged changes after reset: M CONTRIBUTING.md $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: README.md -> README Changes not staged for commit: (use "git add <file>..." to update what will be committed) ...
Find elsewhere
🌐
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.
🌐
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 - In case you are using the Tower ... allows you to undo any wrongfully discarded changes with a simple shortcut: CMD+Z (or CTRL+Z on Windows)!...
🌐
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.
🌐
Graphite
graphite.com › guides › how-to-discard-local-changes-in-git
How to discard local changes in Git
This guide explains the various methods to discard local changes in your Git repository, including using commands like git checkout and git reset.
🌐
Medium
medium.com › @sonal.sadafal › from-panic-to-precision-how-to-safely-discard-git-changes-and-switch-branches-without-4a3604ed9dc3
🌀 From Panic to Precision — How to Safely Discard Git Changes and Switch Branches Without Breaking Anything | by Chaos To Clarity | Medium
October 22, 2025 - Let’s unpack what’s really happening under the hood — and how to safely (or ruthlessly) discard, stash, or reset your changes depending on your goal. Git’s branch switching mechanism (git checkout or git switch) works by changing the HEAD pointer — which moves your working directory to match the target branch’s snapshot. But if your local files differ from what’s stored in the index (staged snapshot), Git blocks the checkout to prevent accidental data loss.
🌐
Atlassian
atlassian.com › git › tutorials › undoing changes
Undoing Changes in Git | Atlassian Git Tutorial
December 15, 2025 - Examining the commit history with git log will now look like: 1git log --oneline 2a1e8fb5 Make some important changes to hello.txt 3435b61d Create hello.txt 49773e52 Initial import · The log output shows the e2f9a78 and 872fa7e commits no longer exist in the commit history. At this point, we can continue working and creating new commits as if the 'crazy' commits never happened. This method of undoing changes has the cleanest effect on history. Doing a reset is great for local changes however it adds complications when working with a shared remote repository.
🌐
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
🌐
Sublime Forum
forum.sublimetext.com › t › reset-all-local-changes › 72198
Reset all local changes - Sublime Merge - Sublime Forum
May 7, 2024 - Is there a way to delete all local changes and reset back to whatever the most current version is? I’ve done some research, and either there’s nothing on this or I’m just using the wrong words to search. Basically, I ju…
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-undo-working-copy-modifications-of-one-file-in-git
How to Undo Working Copy Modifications of One File in Git? - GeeksforGeeks
June 3, 2024 - When working with Git, it's common ... want to discard. Whether it's a file you edited by mistake or a temporary change you no longer need, Git makes it easy to undo modifications to a specific file in your working copy. In this article, we will discuss how to Clone Only a Subdirectory of a Git Repository. In Git, the working copy is your local directory ...
🌐
Git Tower
git-tower.com › learn › git faq › how do i force git pull to overwrite local files?
How do I force git pull to overwrite local files? | Learn Version Control with Git
6 days ago - Force a git pull to overwrite local files: Stash or discard changes & untracked files, then pull. Avoid conflicts with Tower's auto-stashing!
🌐
Linux Hint
linuxhint.com › undo-local-changes-in-git
How to Undo Local Changes in Git – Linux Hint
Git saves the snap of the repository at different points and stores the history of the task. The user can move backward or forward at the particular committed or uncommitted point using git history. The local changes of the repository can undo before publishing to the remote server by discarding all changes or leaving the staged changes.
🌐
Better Stack
betterstack.com › community › questions › how-to-throw-away-local-commits-in-git
How to Throw Away Local Commits in Git | Better Stack Community
If you've already committed your changes and want to discard all commits made after a certain commit: ... Replace <commit> with the commit hash or reference to which you want to reset.
🌐
Opensource.com
opensource.com › article › 18 › 6 › git-reset-revert-rebase-commands
How to reset, revert, and return to previous states in Git | Opensource.com
Using these options can be useful in targeted circumstances such as git reset --hard <commit sha1 | reference>. This overwrites any local changes you haven't committed. In effect, it resets (clears out) the staging area and overwrites content ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › devops › repos › git › undo
Undo changes in your Git repo - Azure Repos | Microsoft Learn
Unstaged files show up in the Changes section. 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.