忽略除某些子目录及其内容之外的所有内容

Ignoring everything except for certain subdirectories and their contents

所以我看到了一些与我相似的帖子,但他们的 none 答案似乎对我有用。

我的文件夹结构如下所示:

|-- identity
|   |-- custom
|   |   |-- pages
|   |   `-- static
|   |-- lib
|   |   `-- ext
|   |-- logs
|   `-- webapps
|-- oxauth
|   |-- custom
|   |   |-- pages
|   |   `-- static
|   |       `-- img
|   |-- lib
|   |   `-- ext
|   |-- logs
|   `-- webapps
`-- oxauth-rp
    |-- logs
    `-- webapps

我想忽略除 custom 文件夹及其内容之外的所有内容。

我试过以下忽略文件:

*
!.gitignore
!/custom/

*
!.gitignore
!/identity/custom/
!/oxauth/custom/

但它忽略了除我的根之外的所有内容。git忽略文件。

至少当我 运行 git 身份时它是这么说的。 custom/pages 文件夹下有文件。 那么,我缺少什么?

根据我的测试,以下应该可以达到预期的效果。

*
!*/
!.gitignore
!/oxauth/custom/**
!/identity/custom/**