假设我有一个像这样的目录结构:
app/
uploads/
.gitkeep
images/
.gitkeep
videos/
.gitkeep
docs/
.gitkeep
我想保留目录结构但不包含其中的文件(显然 .gitkeep
除外)。文档说:
A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
所以,我希望这样可以解决问题:
/app/uploads/**
!/app/uploads/**/.gitkeep
但是这不起作用。没有添加任何子目录。
最佳答案
我使用的结构如下所示:
app/
.gitignore
uploads/
images/
.gitkeep
videos/
.gitkeep
docs/
.gitkeep
我的 app/.gitignore 文件的内容:
uploads/** # Ignore everything in 'uploads' folder
!uploads/**/ # exclude subdirectories
!.gitkeep # and .gitkeep files.
关于git - 我怎样才能 gitignore 目录结构中的文件但保持目录结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22082534/