如何从当前工作树中删除未追踪的本地文件?


当前回答

对于我来说,只有下一个工作:

git clean -ffdx

在所有其他情况下,我收到一些子办公室的“Skipping Directory”消息。

其他回答

用途: git clean [-d] [-f] [-i] [-n] [-q] [-e ] [-x♰ -X] [--]...

-q, --quiet           do not print names of files removed
-n, --dry-run         dry run
-f, --force           force
-i, --interactive     interactive cleaning
-d                    remove whole directories
-e, --exclude <pattern>
                      add <pattern> to ignore rules
-x                    remove ignored files, too
-X                    remove only ignored files

我喜欢 git stash push -u 因为你可以用 git stash pop 放下它们。

编辑: 我也找到了一个方法,以显示未追踪的文件在一个插件(例如 git 显示 stash@{0}^3) https://stackoverflow.com/a/12681856/338986

EDIT2: git stash save 被推翻为 push. 谢谢 @script-wolf。

如果您只想删除被“吉特状态”追踪的文件

git stash save -u
git stash drop "stash@{0}"

我更喜欢“清洁”这个,因为“清洁”会删除被Git忽略的文件,所以你的下一个构建将不得不重建一切,你可能会失去你的IDE设置。

git clean -fd 删除目录

git clean -fX 删除被忽略的文件

git clean -fx 删除被忽略和未被忽略的文件

可以使用上述所有选项,如

清洁 -fdXx

查看 git 手册 获取更多帮助

正常的 git 清洁命令不会用我的 git 版本 2.9.0.windows.1 删除未追踪的文件。

$ git clean -fdx     # doesn't remove untracked files
$ git clean -fdx *   # Append star then it works!