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
🌐
Medium
mehedi-khan.medium.com › a-complete-guide-to-git-reset-hard-and-git-clean-df-713d3f15ddb8
Learn how to use git reset --hard and git clean -df to discard changes and clean your repository. Understand their usage, examples, and precautions. | Medium
February 15, 2025 - Run git reset --hard. The file will revert to its state at the last commit, and your changes will be lost. The git clean -df command removes untracked files and directories from the working directory.
Discussions

Does git reset remove changes made to files?
git reset just unstages all staged changes. It does not modify any files. More on reddit.com
🌐 r/git
11
10
December 21, 2017
How to reset back to zero changes
I've tried git reset --hard but it does not delete files I've created. Right. git reset is a helpful tool, but it does a specific thing. With Git, your files are divided into two categories: tracked and untracked. Tracked files are that Git is keeping track of for you. When you make a Git commit, there's a snapshot of your entire tree of files, and they get included in this snapshot. And if you switch to an older or newer version, a different branch, etc., these files get updated to match. Untracked files are other files in your tree of files that you haven't asked Git to track. When you use git add to include file in a Git commit that you're in the process of creating, a side effect is that the file changes from untracked to tracked. If you never do this (and nobody else does either), then a file stays untracked. Untracked files are useful for stuff like temporary files (that you don't care about) or build output (that you can create by running build commands). As I'm sure you've guessed by now, git reset works on tracked files but leaves untracked files alone (with some very small exceptions). If you want to delete all untracked files, you can use git clean. In your case, you may want to use git clean -d to make it less conservative about what it deletes. Obviously, you want to be careful with git clean since its purpose is to delete stuff. In many cases, you might want to use both git reset and git clean if you really want a clean slate. One more thing: if you've created any commits and you want to get rid of those, you can also use git reset for that. Like a lot of Git commands, it can do a few different things which are only kinda related. It can reset your files to the latest commit on your current branch, or it can change what actually is the latest commit on your current branch. Whether you need to worry about that right now depends on whether you did any commits or not. More on reddit.com
🌐 r/git
2
1
October 31, 2023
command line - git undo all uncommitted or unsaved changes - Stack Overflow
Undoing changes with git reset To discard all local changes to all the files permanently, you can do: ... Save this answer. ... Show activity on this post. For those who reached here searching if they could undo git clean -f -d , by which a file created in eclipse was deleted, More on stackoverflow.com
🌐 stackoverflow.com
git: undo all working dir changes including new files - Stack Overflow
How to delete all changes from working directory including new untracked files. I know that git checkout -f does that, but it doesn't delete new untracked files created since last commit. ... I prefer to go with git stash (saves modified files on a stack) followed by git stash drop (deletes it). ... Save this answer. ... Show activity on this post. git reset ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 reset –hard command reverts uncommitted changes that exist in files that have been added to the index,. This includes files that are newly created files, or files that were previously added to the index and edited since the last commit.
🌐
GitLab
docs.gitlab.com › topics › git › undo
Revert and undo changes | GitLab Docs
The git reset command removes the commit entirely. The git revert command removes the changes, but leaves the commit intact.
🌐
CloudBees
cloudbees.com › blog › git-reset-undo-changes
Git Reset Clearly Explained: How to Undo Your Changes
October 14, 2021 - You can use Git to travel back in time and safely undo your changes in a project through a command called git reset. It can be a tad bit tricky to grasp, so I’ll demystify some underlying concepts for you in this post.
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › devops › repos › git › undo
Undo changes in your Git repo - Azure Repos | Microsoft Learn
In the History tab for the current branch, right-click the commit you want to reset, and then choose Reset > Delete Changes (--hard) to reset the branch to the selected commit and delete all changes to all branch files since that commit.
Find elsewhere
🌐
Better Stack
betterstack.com › community › questions › git-undo-all-working-dir-changes-including-new-files
Git: Undo All Working Dir Changes Including New Files | Better Stack Community
To undo all changes in your working directory, including new files: Discard changes to tracked files with git checkout -- .. Remove untracked files and directories with git clean -fd. Optionally, unstage changes with git reset...
🌐
Reddit
reddit.com › r/git › how to reset back to zero changes
r/git on Reddit: How to reset back to zero changes
October 31, 2023 -

I'm new to git and not much of a programmer, but as I continue on my linux journey I'm running into git more and more. I have a repo that I cloned and selected the branch that I want. I then compiled my kernel (for a riscv sbc). Now this where I'm having trouble. I want to reset everything back to when I just downloaded the repo. I've tried git reset --hard but it does not delete files I've created. I made a test and I can't seem to delete it using git commands. I want to make sure that any other files I've created are gone. I've been just deleting the directory and re cloning it, but there has to be a better way. Thanks

Top answer
1 of 1
5
I've tried git reset --hard but it does not delete files I've created. Right. git reset is a helpful tool, but it does a specific thing. With Git, your files are divided into two categories: tracked and untracked. Tracked files are that Git is keeping track of for you. When you make a Git commit, there's a snapshot of your entire tree of files, and they get included in this snapshot. And if you switch to an older or newer version, a different branch, etc., these files get updated to match. Untracked files are other files in your tree of files that you haven't asked Git to track. When you use git add to include file in a Git commit that you're in the process of creating, a side effect is that the file changes from untracked to tracked. If you never do this (and nobody else does either), then a file stays untracked. Untracked files are useful for stuff like temporary files (that you don't care about) or build output (that you can create by running build commands). As I'm sure you've guessed by now, git reset works on tracked files but leaves untracked files alone (with some very small exceptions). If you want to delete all untracked files, you can use git clean. In your case, you may want to use git clean -d to make it less conservative about what it deletes. Obviously, you want to be careful with git clean since its purpose is to delete stuff. In many cases, you might want to use both git reset and git clean if you really want a clean slate. One more thing: if you've created any commits and you want to get rid of those, you can also use git reset for that. Like a lot of Git commands, it can do a few different things which are only kinda related. It can reset your files to the latest commit on your current branch, or it can change what actually is the latest commit on your current branch. Whether you need to worry about that right now depends on whether you did any commits or not.
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
2.4 Git Basics - Undoing Things
Right below the “Changes to be committed” text, it says use git reset HEAD <file>…​ to unstage.
🌐
W3Schools
w3schools.com › git › git_reset.asp
Git Reset
The git reset command moves your current branch (HEAD) to a different commit. Depending on the option, it can also change which changes are staged or even delete changes from your working directory.
🌐
Atlassian
atlassian.com › git › tutorials › undoing changes
Undoing Changes in Git | Atlassian Git Tutorial
December 15, 2025 - If we invoke git reset --hard a1e8fb5 the commit history is reset to that specified commit. 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 ...
🌐
Git
git-scm.com › docs › git-reset
Git - git-reset Documentation
After inspecting the result of the merge, you may find that the change in the other branch is unsatisfactory. Running git reset --hard ORIG_HEAD will let you go back to where you were, but it will discard your local changes, which you do not want.
🌐
Graphite
graphite.com › guides › git-discard-changes
How to discard changes in Git - Graphite
This command will remove all files ... as these changes cannot be undone. Both of the above commands will leave files explicitly ignored by Git (i.e. files listed in the .gitignore file) intact. To delete ignored files in addition to all of the other untracked files, you can add the -x flag: ... This command resets your working ...
🌐
Medium
medium.com › codex › undo-your-breakfast-meet-git-8-433a1c6cb1e1
How to undo changes in Git? | CodeX
December 29, 2022 - To delete three commits from history, usegit reset --hard HEAD~3. This command can be translated to something like this: “Move the HEAD pointer three steps backward, and recreate the working directory from the current commit”. ... When we ...
Top answer
1 of 16
2625
  • This will unstage all files you might have staged with git add:

      git reset
    
  • This will revert all local uncommitted changes (should be executed in repo root):

      git checkout .
    

    You can also revert uncommitted changes only to particular file or directory:

      git checkout [some_dir|file.txt]
    

    Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory):

      git reset --hard HEAD
    
  • This will remove all local untracked files, so only git tracked files remain:

      git clean -fdx
    

    WARNING: -x will also remove all ignored files, including ones specified by .gitignore! You may want to use -n for preview of files to be deleted.


To sum it up: executing commands below is basically equivalent to fresh git clone from original source (but it does not re-download anything, so is much faster):

git reset
git checkout .
git clean -fdx

Typical usage for this would be in build scripts, when you must make sure that your tree is absolutely clean - does not have any modifications or locally created object files or build artefacts, and you want to make it work very fast and to not re-clone whole repository every single time.

2 of 16
253

If you wish to "undo" all uncommitted changes simply run:

git stash
git stash drop

If you have any untracked files (check by running git status), these may be removed by running:

Warning: This will remove all non-commited data, even what is in .gitignore

git clean -fdx

git stash creates a new stash which will become stash@{0}. If you wish to check first you can run git stash list to see a list of your stashes. It will look something like:

stash@{0}: WIP on rails-4: 66c8407 remove forem residuals
stash@{1}: WIP on master: 2b8f269 Map qualifications
stash@{2}: WIP on master: 27a7e54 Use non-dynamic finders
stash@{3}: WIP on blogit: c9bd270 some changes

Each stash is named after the previous commit messsage.

🌐
Gcapes
gcapes.github.io › git-course › 08-undoing › index.html
Undoing changes – Version control with Git
February 12, 2026 - We are going to use a variant git reset --hard <commit> to reset things to how they were at <commit>. This is a permanent undo which deletes all changes more recent than <commit> from your history.
Top answer
1 of 16
2019
git reset --hard # removes staged and working directory changes

## !! be very careful with these !!
## you may end up deleting what you don't want to
## read comments and manual.
git clean -f -d # remove untracked
git clean -f -x -d # CAUTION: as above but removes ignored files like config.
git clean -fxd :/ # CAUTION: as above, but cleans untracked and ignored files through the entire repo (without :/, the operation affects only the current directory)

To see what will be deleted before-hand, without actually deleting it, use the -n flag (this is basically a test-run). When you are ready to actually delete, then remove the -n flag:

git clean -nfd

2 of 16
440

Safest method, which I use frequently:

git clean -fd

Syntax explanation as per /docs/git-clean page:

  • -f (alias: --force). If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given.
  • -d. Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.

As mentioned in the comments, it might be preferable to do a git clean -nd which does a dry run and tells you what would be deleted before actually deleting it.

Link to git clean doc page: https://git-scm.com/docs/git-clean

🌐
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
3 days ago - Discard uncommitted changes with git restore. Covers discarding working directory changes, unstaging files, and restoring from specific commits.