First, it's always worth noting that git reset --hard is a potentially dangerous command, since it throws away all your uncommitted changes. For safety, you should always check that the output of git status is clean (that is, empty) before using it.

Initially you say the following:

So I know that Git tracks changes I make to my application, and it holds on to them until I commit the changes, but here's where I'm hung up:

That's incorrect. Git only records the state of the files when you stage them (with git add) or when you create a commit. Once you've created a commit which has your project files in a particular state, they're very safe, but until then Git's not really "tracking changes" to your files. (for example, even if you do git add to stage a new version of the file, that overwrites the previously staged version of that file in the staging area.)

In your question you then go on to ask the following:

When I want to revert to a previous commit I use: git reset --hard HEAD And git returns: HEAD is now at 820f417 micro

How do I then revert the files on my hard drive back to that previous commit?

If you do git reset --hard <SOME-COMMIT> then Git will:

  • Make your current branch (typically master) back to point at <SOME-COMMIT>.
  • Then make the files in your working tree and the index ("staging area") the same as the versions committed in <SOME-COMMIT>.

HEAD points to your current branch (or current commit), so all that git reset --hard HEAD will do is to throw away any uncommitted changes you have.

So, suppose the good commit that you want to go back to is f414f31. (You can find that via git log or any history browser.) You then have a few different options depending on exactly what you want to do:

  • Change your current branch to point to the older commit instead. You could do that with git reset --hard f414f31. However, this is rewriting the history of your branch, so you should avoid it if you've shared this branch with anyone. Also, the commits you did after f414f31 will no longer be in the history of your master branch.
  • Create a new commit that represents exactly the same state of the project as f414f31, but just adds that on to the history, so you don't lose any history. You can do that using the steps suggested in this answer - something like:

    git reset --hard f414f31
    git reset --soft HEAD@{1}
    git commit -m "Reverting to the state of the project at f414f31"
    
Answer from Mark Longair on Stack Overflow
🌐
Git
git-scm.com › docs › git-reset
Git - git-reset Documentation
Reset the index and update the files in the working tree that are different between <commit> and HEAD, but keep those which are different between the index and working tree (i.e. which have changes which have not been added). Mainly exists to reset unmerged index entries, like those left behind by git am -3 or git switch -m in certain situations.
Top answer
1 of 2
1523

First, it's always worth noting that git reset --hard is a potentially dangerous command, since it throws away all your uncommitted changes. For safety, you should always check that the output of git status is clean (that is, empty) before using it.

Initially you say the following:

So I know that Git tracks changes I make to my application, and it holds on to them until I commit the changes, but here's where I'm hung up:

That's incorrect. Git only records the state of the files when you stage them (with git add) or when you create a commit. Once you've created a commit which has your project files in a particular state, they're very safe, but until then Git's not really "tracking changes" to your files. (for example, even if you do git add to stage a new version of the file, that overwrites the previously staged version of that file in the staging area.)

In your question you then go on to ask the following:

When I want to revert to a previous commit I use: git reset --hard HEAD And git returns: HEAD is now at 820f417 micro

How do I then revert the files on my hard drive back to that previous commit?

If you do git reset --hard <SOME-COMMIT> then Git will:

  • Make your current branch (typically master) back to point at <SOME-COMMIT>.
  • Then make the files in your working tree and the index ("staging area") the same as the versions committed in <SOME-COMMIT>.

HEAD points to your current branch (or current commit), so all that git reset --hard HEAD will do is to throw away any uncommitted changes you have.

So, suppose the good commit that you want to go back to is f414f31. (You can find that via git log or any history browser.) You then have a few different options depending on exactly what you want to do:

  • Change your current branch to point to the older commit instead. You could do that with git reset --hard f414f31. However, this is rewriting the history of your branch, so you should avoid it if you've shared this branch with anyone. Also, the commits you did after f414f31 will no longer be in the history of your master branch.
  • Create a new commit that represents exactly the same state of the project as f414f31, but just adds that on to the history, so you don't lose any history. You can do that using the steps suggested in this answer - something like:

    git reset --hard f414f31
    git reset --soft HEAD@{1}
    git commit -m "Reverting to the state of the project at f414f31"
    
2 of 2
321

WARNING: git clean -f will remove untracked files, meaning they're gone for good since they aren't stored in the repository. Make sure you really want to remove all untracked files before doing this.


Try this and see git clean -f.

git reset --hard will not remove untracked files, where as git-clean will remove any files from the tracked root directory that are not under Git tracking.

Alternatively, you can do the following (beware though - that removes all ignored files too)

  • git clean -df
  • git clean -xdf CAUTION! This will also delete ignored files

Explanation of Flags:

-d deletes all files in directories recursively

-f

If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f or -i. Git will refuse to modify untracked nested git repositories (directories with a .git subdirectory) unless a second -f is given.

-x Don't use standard ignore rules but ones specified by -e. This can be used to start a clean build.

Source: Man pages

Discussions

Is my understanding of Git Reset Correct?
git reset --hard resets changes in the current working directory. If I'm ever in doubt about git and can't be bothered reading the documentation (the man pages are actually pretty good, but still...), I just make a new git, commit some meaningless text, and try out the command. More on reddit.com
🌐 r/git
16
15
August 26, 2021
git reset --hard

--force

I SURE HOPE YOU KNOW WHAT YOU'RE DOING

More on reddit.com
🌐 r/ProgrammerHumor
314
22636
January 15, 2020
TIL how to undo: git reset --hard HEAD@{1}
Watch out! This might not do what you think. HEAD@{1} would be the last commit where you were. So if you git checkout master; git reset --hard HEAD@{1} you'd be resetting the tip of your master branch to whatever you were looking at before, NOT YOUR LAST COMMIT ON THAT BRANCH. Read git help reflog for more info More on reddit.com
🌐 r/git
14
0
June 8, 2017
Git Reset Demystified

I think this is an updated version: https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified

More on reddit.com
🌐 r/git
2
12
January 14, 2016
🌐
Atlassian
atlassian.com › git › tutorials › undoing changes › git reset
Git Reset | Atlassian Git Tutorial
Git reset is a powerful command that is used to undo local changes to the state of a Git repo. Explore its 3 primary forms of invocation in this article.
🌐
Codecademy
codecademy.com › article › what-is-git-reset-explained-with-examples
What is Git Reset? Explained with Examples | Codecademy
This command tells Git to move the HEAD pointer one commit back and reset both the working directory and staging area to that earlier state. All uncommitted changes — whether staged or unstaged — are permanently deleted.
🌐
W3Schools
w3schools.com › git › git_reset.asp
Git Reset
The git reset command moves your current branch (HEAD) to a different commit.
Find elsewhere
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
Git - Undoing Things
Right below the “Changes to be committed” text, it says use git reset HEAD <file>…​ to unstage.
🌐
GitKraken
gitkraken.com › home › learn › git reset
Git Reset | Hard, Soft & Mixed | Learn Git
March 26, 2026 - Git reset allows you to move the HEAD to a previous commit, undoing the changes between your starting state and specified commit. Learn how to use Git reset hard and soft.
🌐
Graphite
graphite.com › guides › how-to-use-git-reset-head
How to use Git reset HEAD
The git reset command is a powerful tool used to undo changes in a Git repository. It can be used to unstage files, alter commits, and even delete changes altogether. This guide explains the different modes of using git reset, particularly focusing ...
🌐
GitHub
gist.github.com › stevenyap › 7511407
Git reset and revert: Undoing changs · GitHub
# If you are pulling, rebasing ... files # git clean -f -d will remove newly created files and directories (BEWARE!) git reset --hard # reset to the last commit # HEAD is the current commit, HEAD^ is the last commit # HEAD~2 ...
🌐
Medium
medium.com › @yairwebdev › how-to-understand-git-reset-so-you-dont-afraid-to-use-it-67d3856008b7
Let’s Learn Git Reset With Practical Example | Medium
May 29, 2022 - We all have a moment when we want to abort some code we committed, so let's learn how to do that in a safe way.
🌐
Simon Dosda
simondosda.github.io › posts › 2022-01-04-git-reset.html
Git reset, when and how to use it | Simon Dosda
January 4, 2022 - When used with a path, the reset command does the opposite of git add: it removes changes from the staging area.
🌐
Linux Kernel
kernel.org › pub › software › scm › git › docs › git-reset.html
git-reset(1)
January 20, 2026 - Reset the index and update the files in the working tree that are different between <commit> and HEAD, but keep those which are different between the index and working tree (i.e. which have changes which have not been added). Mainly exists to reset unmerged index entries, like those left behind by git am -3 or git switch -m in certain situations.
🌐
freeCodeCamp
freecodecamp.org › news › git-reset-hard-how-to-reset-to-head-in-git
Git Reset Hard – How to Reset to Head in Git
April 10, 2023 - In the two screenshots above, the HEAD is the commit hash d8cd0ee, with the commit message Linked JavaScript file. It is the previous commit I made. To reset the codebase to that commit, I would run git reset --hard HEAD:
🌐
Medium
meghasharmaa704.medium.com › what-is-git-reset-273c9c0c1043
What is Git Reset?. Git reset is a command in the Git… | by Meghasharmaa | Medium
November 28, 2025 - The git reset command is used to undo the changes in your working directory and get back to a specific commit while discarding all the commits made after that one.
🌐
Git
git-scm.com › book › en › v2 › Git-Tools-Reset-Demystified
Git - Reset Demystified
This isn’t the same as changing HEAD itself (which is what checkout does); reset moves the branch that HEAD is pointing to. This means if HEAD is set to the master branch (i.e. you’re currently on the master branch), running git reset 9e5e6a4 will start by making master point to 9e5e6a4.
🌐
GitBreeze
gitbreeze.dev › git-reset-hard
How to Git Reset Hard Effortlessly | GitBreeze
July 25, 2021 - It won't replace any working files ... will roll back the last commands that have affected your branches. If you need to undo the last command that affected your branches, you can use the git reset command to tell the Git reflog to go back to its penultimate state...
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Git-reset-hard-vs-soft-Whats-the-difference
Git reset hard vs. soft: What's the difference?
Let’s imagine the developer wants to git reset back to commit #3 (id ebbbca3). The developer can choose either of the two git reset syntaxes: ... If the developer performs a git reset hard, this removes files d.txt and e.txt from the filesystem, and the staging index is cleared if anything exists in it.
🌐
Fork
git-fork.com
Fork - a fast and friendly git client for Mac and Windows
Fork - a fast and friendly git client for Mac and Windows.
🌐
Davidvarghese
notes.davidvarghese.net › software-engineering › devops › git › commands › git-revert-and-reset-command
Git Revert & Reset Command
January 28, 2024 - # Delete multiple commit and go back in time # The files from the deleted commits will show as upstaged git reset --mixed <commit-id> # Delete commits and the changes to the files git reset --hard <commit-id> # Delete commits and modified files show up as staged files git reset --soft <commit-id> # Remove files from staging area git reset HEAD <filename>