如何使用 git 来跟踪文件夹结构?
how can I use git to track folder structure?
我尝试使用 .gitkeep,但无论我怎么尝试,它都不起作用。
例如我有这样的文件夹结构:
.
├── a
│ ├── aa
│ │ ├── aaa
│ │ │ ├── .gitkeep
│ │ │ └── test.txt
│ │ ├── .gitkeep
│ │ └── test.txt
│ ├── .gitkeep
│ └── test.txt
├── b
│ ├── bb
│ │ ├── bbb
│ │ │ └── test.txt
│ │ ├── .gitkeep
│ │ └── test.txt
│ └── test.txt
└── .gitignore
我有这样的 .gitignore:
*
!a/.gitkeep
!*/.gitkeep
!**/.gitkeep
!.gitignore
想法是用 .gitkeep 保留所有文件夹。令人惊讶的是,此配置不会跟踪任何文件夹。
谁能告诉我为什么这不起作用?
Can anyone tell me why this does not not work?
为此,你有 git check-ignore -v
其次,it is not possible to re-include a file if a parent directory of that file is excluded
并且 *
也会忽略文件夹,使所有其他排除规则都没有实际意义。
要排除 .git只保留(并忽略保留文件夹的内容),只忽略文件,然后将文件夹列入白名单,最后排除(在所有忽略的文件中).gitkeep
个。
/**
!/**/
!.gitkeep
但是如果目标是不忽略文件夹中有.gitkeep
的任何文件,那么您需要一个一个地排除任何文件夹:
/**
!/**/
!/a/aa/aaa/**
!/b/bb/bbb/**
我尝试使用 .gitkeep,但无论我怎么尝试,它都不起作用。
例如我有这样的文件夹结构:
.
├── a
│ ├── aa
│ │ ├── aaa
│ │ │ ├── .gitkeep
│ │ │ └── test.txt
│ │ ├── .gitkeep
│ │ └── test.txt
│ ├── .gitkeep
│ └── test.txt
├── b
│ ├── bb
│ │ ├── bbb
│ │ │ └── test.txt
│ │ ├── .gitkeep
│ │ └── test.txt
│ └── test.txt
└── .gitignore
我有这样的 .gitignore:
*
!a/.gitkeep
!*/.gitkeep
!**/.gitkeep
!.gitignore
想法是用 .gitkeep 保留所有文件夹。令人惊讶的是,此配置不会跟踪任何文件夹。
谁能告诉我为什么这不起作用?
Can anyone tell me why this does not not work?
为此,你有 git check-ignore -v
其次,it is not possible to re-include a file if a parent directory of that file is excluded
并且 *
也会忽略文件夹,使所有其他排除规则都没有实际意义。
要排除 .git只保留(并忽略保留文件夹的内容),只忽略文件,然后将文件夹列入白名单,最后排除(在所有忽略的文件中).gitkeep
个。
/**
!/**/
!.gitkeep
但是如果目标是不忽略文件夹中有.gitkeep
的任何文件,那么您需要一个一个地排除任何文件夹:
/**
!/**/
!/a/aa/aaa/**
!/b/bb/bbb/**