```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
```git clean``` not removing sub-directories (not recursive)
提问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 xyz
folder, but I want to remove the file_2
inside it.
我不想删除xyz
文件夹,但我想删除其中的file_2
内容。
Why is git clean
is not working recursively?
为什么git clean
不是递归工作?
回答by manojlds
If you have it in ignore, use git clean -xf
. You can do git clean -xdf
but that will also remove untracked directories. Use -n
for 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 -xdf
might 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
rscharfe
szeder
gitster
gitster
clean
: show an error message when the path is too longWhen
lstat()
failed,git clean
would 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/git
issue 521Note that we temporarily set
core.longpaths = false
in the regression test; this ensures forward-compatibility with thecore.longpaths
feature 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 xyz
directory in your .gitignore
file somewhere? You can override this behaviour using the -x
switch to clean
. Also, if the xyz
directory is not tracked (has nothing inside it that is tracked), it will not be removed unless you pass the -d
option.
也许您的xyz
文件中有该目录.gitignore
?您可以使用-x
切换到来覆盖此行为clean
。此外,如果xyz
目录未被跟踪(其中没有任何被跟踪的内容),除非您传递该-d
选项,否则它不会被删除。