使用 git 删除非存储库文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5037480/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:07:57  来源:igfitidea点击:

Removing non-repository files with git?

git

提问by Scott

I'm writing Autotools code and in the process of development, tons of files are generated.

我正在编写 Autotools 代码,在开发过程中,生成了大量文件。

Is there anyway to tell git to remove all files from a directory that are not part of the repository?

无论如何要告诉 git 从不属于存储库的目录中删除所有文件?

回答by Lily Ballard

You can use git-clean. This command will remove untracked files/directories. By default, it will only print what it would have removed, without actually removing them.

您可以使用git-clean。此命令将删除未跟踪的文件/目录。默认情况下,它只会打印它会删除的内容,而不会实际删除它们。

Given the -fflag to remove the files, and the -dflag to remove empty directories as well :

鉴于-f删除文件的-d标志,以及删除空目录的标志:

git clean -df

Also removing ignored files :

同时删除被忽略的文件:

git clean -dfx