git - 为什么 git clean -dfX 不删除 .gitignore 中的 lib 文件?

标签 git static-libraries

我确信 *.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/

相关文章:

mysql - Git环境设置。需要建议

c++ - 32 位与 64 位库修饰

git - 重置为 Git 中的第一个提交?

git - 如何在 TFS 2012 Update 2(自托管)中启用 GIT 支持

git:分支删除了一些提交

git - 从忘记 .gitignore 中恢复

c - 静态库不包含宏

iphone - 静态库 .a 文件在 .m 文件中执行更改后未更新

c - 在 VS2008/VC 项目中使用 .lib 时出现问题

c - 看来 setlocale() 在链接库中不起作用