如何删除使用递归…/**模式忽略的.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