How Do I Revert All Local Changes in Git Managed Project to Previous State?

Better Stack Team
Updated on June 24, 2024

To revert all local changes in a Git-managed project to the state of the previous commit, you can use the following commands:

git reset --hard HEAD

This command resets the current branch to the state of the HEAD commit, which is the last commit on the current branch. The --hard option discards all changes in the working directory and staging area, reverting the repository to the state of the previous commit.


  • Be cautious when using git reset --hard, as it permanently removes all local changes, including uncommitted work. Make sure you don't have any important changes that you want to keep.
  • If you have any untracked files in your working directory that you want to keep, make sure to back them up before running the command, as git reset --hard will delete untracked files.
Got an article suggestion? Let us know
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github