告诉 git 可以删除未跟踪的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7588268/
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
Telling git its ok to remove untracked files
提问by zkolnik
Possible Duplicate:
How do you remove untracked files from your git working copy?
可能的重复:
如何从 git 工作副本中删除未跟踪的文件?
Is it possible to tell git to remove untracked files? Mainly something that is similar to a reset?
是否可以告诉 git 删除未跟踪的文件?主要是类似于重置的东西?
example:
例子:
git checkout -- index.php <-- revert my file
git checkout -- master <-- this would revert the entire repo back to the last commit on master, removing (deleting) any and all untracked files as well as reverting committed ones.
I know this is trivial to do on the shell. But I'd like to know if this can be done in Git?
我知道这在 shell 上是微不足道的。但我想知道这是否可以在 Git 中完成?
采纳答案by Greg Hewgill
You may be looking for git clean
. This will delete all untracked files. By default this ignores (does not delete) patterns in .gitignore
, but git clean -x
cleans those files too.
您可能正在寻找git clean
. 这将删除所有未跟踪的文件。默认情况下,这会忽略(不删除)中的模式.gitignore
,但git clean -x
也会清理这些文件。
From the git clean
man page:
从git clean
手册页:
-x
Don't use the ignore rules. This allows removing all untracked
files, including build products. This can be used (possibly in
conjunction with git reset) to create a pristine working directory
to test a clean build.
回答by Adam Dymitruk
You need git clean
but add the -df
to enable removing files that are in directories from where you are. Add x
to include ignored files.
您只需要git clean
添加-df
即可从您所在的目录中删除文件。添加x
以包含被忽略的文件。
So to completely clean your working directory leaving only what is in source control, issue this command:
因此,要完全清理您的工作目录,只留下源代码管理中的内容,请发出以下命令:
git clean -xdf