Using git, how do you reset the working tree (local file system state) to the state of the index ("staged" files)?
I tend to use git checkout .
which discards all changes from the working directory down. This makes a difference if you're not at the root of the repository.
This command doesn't remove newly created files which is usually a good thing. If you need to do this then you can use git clean
as well.
You can use git stash save --keep-index
to do this. After saving the stash, you can use git stash drop
if you don't want to keep it around.
You can use git-checkout-index (git checkout-index
). Be aware that you need to add
-
-f
to force it to overwrite existing files, or -
-f -a
to enforce overwriting all paths in the index.