Situation:
Now we have three different states. The state of HEAD, the state
git checkout :/
discards all changes in the working tree and replaces it with what's in the index, regardless of the current working directory.
https://git-scm.com/docs/gitglossary#gitglossary-aiddefpathspecapathspec
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. 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.