Reset all changes after last commit in git

Dogbert picture Dogbert · Jan 7, 2011 · Viewed 167.1k times · Source

How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?

Answer

Benjamin Bannier picture Benjamin Bannier · Jan 7, 2011

First, reset any changes

This will undo any changes you've made to tracked files and restore deleted files:

git reset HEAD --hard

Second, remove new files

This will delete any new files that were added since the last commit:

git clean -fd

Files that are not tracked due to .gitignore are preserved; they will not be removed

Warning: using -x instead of -fd would delete ignored files. You probably don't want to do this.