git checkout 所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29007821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git checkout all the files
提问by fedorqui 'SO stop harming'
How can I get rid of all the changes in all the files of my repository?
如何摆脱存储库中所有文件中的所有更改?
Say I am in a branch and I did some changes. git status
returns a set of files in the "Changes not staged for commit" and I notice I would like to get rid of all of these changes in all the files. How can I do this with a single command?
假设我在一个分支,我做了一些改变。git status
在“未暂存的更改”中返回一组文件,我注意到我想删除所有文件中的所有这些更改。如何使用单个命令执行此操作?
I know I can do the following to checkout just one file:
我知道我可以执行以下操作来只检出一个文件:
git checkout -- <file>
I noticed that git checkout --
alone returns the list of all uncommited files. However, I cannot find a way to checkout all of them, something like git checkout --all
.
我注意到git checkout --
只有返回所有未提交文件的列表。但是,我找不到一种方法来结帐所有这些,例如git checkout --all
.
I checked man git checkout
and could not find anything. Also I saw Git: Checkout all files except oneand tried git checkout .
and did not work either.
我检查过man git checkout
,找不到任何东西。我还看到了Git: Checkout all files except one并尝试过git checkout .
但也没有工作。
Would I have to do it programmatically, by looping through the git checkout --
output?
我是否必须通过循环git checkout --
输出以编程方式执行此操作?
回答by poke
If you are at the root of your working directory, you can do git checkout -- .
to check-out all files in the current HEAD and replace your local files.
如果您位于工作目录的根目录,您可以git checkout -- .
检出当前 HEAD 中的所有文件并替换您的本地文件。
You can also do git reset --hard
to reset your working directory and replace all changes (including the index).
您还git reset --hard
可以重置工作目录并替换所有更改(包括索引)。
回答by Singhak
Other way which I found useful is:
我发现有用的其他方法是:
git checkout <wildcard>
Example:
例子:
git checkout *.html
More generally:
更普遍:
git checkout <branch> <filename/wildcard>