Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何删除使用递归…/**模式忽略的.git文件?_Git - Fatal编程技术网

如何删除使用递归…/**模式忽略的.git文件?

如何删除使用递归…/**模式忽略的.git文件?,git,Git,以下是设置: git init echo "foo/**" > .gitignore mkdir foo && touch foo/bar git status --ignored 打印状态显示: ... Ignored files: (use "git add -f <file>..." to include in what will be committed) foo/ 。。。它什么也不做foo/bar

以下是设置:

git init
echo "foo/**" > .gitignore
mkdir foo && touch foo/bar
git status --ignored
打印状态显示:

...
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)
    foo/
。。。它什么也不做<代码>foo/bar仍然存在

请注意,如果我将
.gitignore
规则从
foo/**
更改为
foo/
,则
-fdX
命令将按预期工作-它将删除
foo/
文件夹


使用git版本2.29.1进行测试

我使用git for Windows进行了测试,第一个问题来自双引号:

echo“foo/**”>.gitignore
这将为您提供一个
.gitignore
文件,其中包含:

"foo/**"
这足以忽略
foo
文件夹,但不能忽略其内容:
git检查ignore-v--foo\bar将不返回任何内容

如“”所述,使用:

echo | set/p=“foo/**”>.gitignore 这样,您就有了一个
.gitignore

foo/**
git-check-ignore-v--foo\bar

$git检查忽略-v foo/bar
.gitignore:1:foo/foo/bar
但在这两种情况下,
gitclean-nfdX
不会删除任何内容

只有直接提到该文件,git clean才会提议做任何事情:

vonc@voncMINGW64/d/git/tests/ign/foo(master)
$git clean-nX
vonc@voncMINGW64/d/git/tests/ign/foo(master)
$git clean-nX条
我会移除酒吧
要使其真正起作用,您的规则不应使用“
**

echo | set/p=“foo/”>.gitignore 然后,
git clean-ndX
就可以工作了

D:\git\tests\ign>git clean-ndX
我会移除foo/

tl;dr:git clean-X中的一个明显错误的解决方法是:

git ls-files -oi --exclude-standard -z | xargs -0 rm
没有
-z | xargs-0 rm
的是
git clean-nX
,有它的是
git clean-fX
。要(递归地)删除空目录,
find*-depth-type d-empty-delete


在linux上,在

mkdir t1 t2 t3
touch t1/a1 t2/a2 t3/a3
printf %s\\n 't1/**' 't2/*' 't3' >.git/info/exclude
接下来的两个命令列出了不同的结果:

git ls-files -oc|git check-ignore --stdin
git clean -nX
但是

touch t1/c1 t2/c2 t3/c3
git add -f t?/c?
git clean -nX
然后,
git clean
拿起
t?/a?
垃圾桶。所以clean不会递归到
-X
的完全被忽略的目录中

编辑:更糟糕的是,在忽略列表中将
t3
替换为
a3
,并在
c?
文件消失或未跟踪的情况下重新运行,使
a3
仍然保持不变。所以它甚至不是“完全被忽略”的目录,而是“没有跟踪内容的目录”


是啊,这里有些东西需要修复。

这可能是个bug。我并不完全清楚
**
git clean-X
的预期行为是什么,但您应该将此示例发送到git邮件列表。分析得很好。向上投票。
touch t1/c1 t2/c2 t3/c3
git add -f t?/c?
git clean -nX