How to quickly undo staged and unstaged changes in git?
git reset HEAD
git checkout .
git reset HEAD
will unstage all changes and git checkout .
discards all the changes.
You need to use two commands: git reset --hard
and git clean -fd
.git reset --hard
will undo all staged changes and git clean -fd
, unstaged changes (files and directories). You can create a alias that will do the two commands. For that, just add the following lines in your .gitconfig
:
[alias]
undo = '!git reset --hard && git clean -fd'
You can use git clean
$ git status -s ?? oops.txt $ git clean -f Removing oops.txt $ git status -s
More info:
Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.