我确信 *.lib 位于 .gitignore
cat .gitignore | grep lib
*.lib
$ ls lib
TLib.lib TLib_d.lib
$ git status
# On branch master
nothing to commit (working directory clean)
$ git clean -dfX
$ ls lib
TLib.lib TLib_d.lib // the issue is here...
为什么这些.lib文件没有被删除?
最佳答案
一旦遇到不在索引中的目录,Git 就会停止搜索文件。但在上面的例子中,我们告诉 git 搜索所有匹配忽略模式的文件。所以,最好进入所有目录并搜索文件。
这也将匹配 git ls-files 行为。鉴于:
$ tree
.
├── foo.o
└── lib
├── TLib_d.lib
└── TLib.lib
1 directory, 3 files
$ cat .gitignore
*.lib
运行以下命令。
$ git ls-files -o
foo.o
lib/TLib.lib
lib/TLib_d.lib
$ git ls-files -o -i --exclude-standard
lib/TLib.lib
lib/TLib_d.lib
$ git clean -n
Would remove foo.o
Would not remove lib/
$ git clean -nd
Would remove foo.o
Would remove lib/
$ git clean -nX
最后一个命令不打印任何文件。但如果能做到的话那就太好了:
$ git clean -nX
Would not remove foo.o
Would not remove lib/
Would remove lib/TLib.lib
Would remove lib/TLib_d.lib
关于git - 为什么 git clean -dfX 不删除 .gitignore 中的 lib 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12024443/