git revert local changes-How do I revert all local changes in Git managed project to previous state?


I have a project in which I ran git init. After several commits, I did git status which told me everything was up to date and there were no local changes.

Then I made several consecutive changes and realized I wanted to throw everything away and get back to my original state. Will this command do it for me?

git reset --hard HEAD



You can remove the untracked files using the git clean command. It completes both the git reset and git checkout commands. It will remove any files that are not under version control in the current directory. Use the below command.

git clean -fd


You can revert any unstaged changes in your working copy by using the checkout command.

git checkout .

If you have staged changes, you can revert them using the reset command.

git reset

And then use the git checkout command to revert all local changes.


If you want to unleash your potential in this competitive field, please visit the DevOps course page for more information, where you can find the DevOps tutorials and DevOps frequently asked interview questions and answers as well.


This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.