```git clean``` 不删除子目录(非递归)

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

```git clean``` not removing sub-directories (not recursive)

git

提问by Ankita

I am facing problems with git clean. Consider the following scenario:

我正面临git clean. 考虑以下场景:

git status -su
?? file_1
?? xyz/file_2

git clean -f
Not removing xyz/file_2
Removing file_1

I don't want to remove the xyzfolder, but I want to remove the file_2inside it.

我不想删除xyz文件夹,但我想删除其中的file_2内容。

Why is git cleanis not working recursively?

为什么git clean不是递归工作?

回答by manojlds

If you have it in ignore, use git clean -xf. You can do git clean -xdfbut that will also remove untracked directories. Use -nfor a dry-run.

如果您将其忽略,请使用git clean -xf. 您可以这样做,git clean -xdf但这也会删除未跟踪的目录。使用-n的干式运行。

http://gitready.com/beginner/2009/01/16/cleaning-up-untracked-files.html

http://gitready.com/beginner/2009/01/16/cleaning-up-untracked-files.html

回答by Biga

Also, git clean doesn't work up the directory tree. Consider you have

此外, git clean 不会在目录树上工作。考虑你有

> git status
Untracked files:
  ../file1.orig
  ../../file2.orig

git clean -df would do nothing in this state. You have to 'cd' into the project root and run 'git clean -df' there again.

git clean -df 在这种状态下什么也不做。您必须“cd”进入项目根目录并再次在那里运行“git clean -df”。

回答by mario

try this:

尝试这个:

git clean -xdf

let me know if that worked.

让我知道这是否有效。

回答by VonC

Note that, on Widows, even a git clean -xdfmight fail, silentlyskipping a path when it cannot lstat()it; now (Git 2.23, Q3 2019), it gives a warning.

请注意,在 Widows 上,即使 agit clean -xdf也可能失败,当它不能时默默地跳过一条路径lstat();现在(Git 2.23,2019 年第三季度),它发出警告。

See commit b09364c(18 Jul 2019) by Johannes Schindelin (dscho).
Helped-by: René Scharfe (rscharfe), SZEDER Gábor (szeder), and Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster--in commit f3d508f, 25 Jul 2019)

请参阅Johannes Schindelin ( ) 的提交 b09364c(2019 年 7 月 18 日。 帮助者:René Scharfe ( )SZEDER Gábor ( )Junio C Hamano ( )(由Junio C Hamano合并-- --提交 f3d508f 中,2019 年 7 月 25 日)dscho
rscharfeszedergitster
gitster

clean: show an error message when the path is too long

When lstat()failed, git cleanwould abort without an error message, leaving the user quite puzzled.

In particular on Windows, where the default maximum path length is quite small (yet there are ways to circumvent that limit in many cases), it is very important that users be given an indication why their command failed because of too long paths when it did.

This test case makes sure that a warning is issued that would have helped the user who reported git-for-windows/gitissue 521

Note that we temporarily set core.longpaths = falsein the regression test; this ensures forward-compatibility with the core.longpathsfeature that has not yet been upstreamed from Git for Windows.

clean: 当路径太长时显示错误信息

lstat()失败时,git clean会在没有错误消息的情况下中止,让用户感到非常困惑。

特别是在 Windows 上,默认的最大路径长度非常小(但在许多情况下有办法规避该限制),向用户提供指示为什么他们的命令由于路径太长而失败是非常重要的.

此测试用例确保发出警告,以帮助报告问题 521的用户git-for-windows/git

注意我们core.longpaths = false在回归测试中临时设置;这确保了与core.longpaths尚未从 Git for Windows 上游的功能向前兼容。

回答by Noufal Ibrahim

Perhaps you have the xyzdirectory in your .gitignorefile somewhere? You can override this behaviour using the -xswitch to clean. Also, if the xyzdirectory is not tracked (has nothing inside it that is tracked), it will not be removed unless you pass the -doption.

也许您的xyz文件中有该目录.gitignore?您可以使用-x切换到来覆盖此行为clean。此外,如果xyz目录未被跟踪(其中没有任何被跟踪的内容),除非您传递该-d选项,否则它不会被删除。