With .gitignore
:
foo/
和一个 git 存储库:
./quux
./quux/foo
./quux/foo/bar
./quux/foo/bar/baz
As foo
被忽略,git 假设工作目录是干净的:
% git status
# On branch master
nothing to commit, working directory clean
The git clean -ndx
prints:
% git clean -ndx
Would remove quux/
But git clean -ndX
不打印任何内容。我希望它能删除quux/
以及。
这是一个错误还是我不明白的某些 gitignore 功能?
如果我添加一些文件到quux
并提交它。比 git clean 会尝试删除quux/foo/
正如预期的那样。
我的 git 很新:git version 1.8.3.4
.
$ git init .
$ echo foo/ >.gitignore
$ git add .;git commit -am ignore
$ mkdir -p foo/bar bar/foo
$ touch foo/bar/1 bar/foo/1
$ git clean -ndx
Would remove bar/
Would remove foo/
$ git clean -ndX
Would remove foo/
$
git help clean
says:
-X
Remove only files ignored by Git. This may be useful to rebuild
everything from scratch, but keep manually created files.
这意味着它不会删除手动创建的内容,除非明确忽略它。
在这种情况下bar
目录是手动创建的并且没有显式忽略,因此不会被删除。
对于你来说也是如此quux
目录。
要“修复”此问题,您需要添加bar
通过添加文件来控制git控制的目录:
$ touch bar/x
$ git add bar/x
$ git commit -am add\ x
$ git clean -ndX
Would remove bar/foo/
Would remove foo/
$
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)