What is the git command to remove all changes and revert to the state of your last commit?

I made a lot of useless changes and would like to return to the state in which my repo was, before any changes.

Is there a git command for this?

Thank!

+3
source share
2 answers

Firstly, to undo changes in tracked files:

git reset --hard HEAD

git resetonly resets the index; adding --hardalso resets the working copy. If you have already done this, specify a different commit for reset to - eg HEAD^, to return to the parent commit HEAD(i.e., delete the last commit).

Next, to delete all unopened files:

git clean -dfx

-d , , -f , -x .gitignore d.

+6

, - , git reset --hard HEAD^

, , git reset --hard HEAD

+3

All Articles