how to clear all files from the git from the "Changed but not updated:" list
I have a list of files in my "Changed but not updated:" list which git has picked up as h开发者_如何学运维aving changed but there are no changes in the files themselves
I've added all the files that have changes so I simply want to clear the "Changed but not updated:" list.
How can I do this?
git checkout .
seems to do the trick for me. This is hinted at in the message shown by git status
, though it usually mentions giving a file as an argument. checkout
with paths set the contents of the working tree to match the index (which should contain the files you selected with git add
).
From the man page:
git checkout [--patch] [<tree-ish>] [--] <pathspec>…
When or --patch are given, git checkout does not switch branches. It updates the named paths in the working tree from the index file or from a named (most often a commit). In this case, the -b and --track options are meaningless and giving either of them results in an error. The argument can be used to specify a specific tree-ish (i.e. commit, tag or tree) to update the index for the given paths before updating the working tree.
If you have files in the staging area, you should use :
git checkout -- [path to files]
If you have committed your changes already, you can do :
git reset --hard HEAD
You should either use:
git add <file>
to add the file into the staged changes,
or
git checkout -- <file>
to reset it back to what is currently staged.
This is explained in the git status
message:
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
Or if you want to blow away all your changes (including staged changes) use:
git reset --hard HEAD
This will do the trick to clean "Changes not staged for commit"
git checkout -- .
精彩评论