Search code examples
gitgitignore

Ignoring everything except for certain subdirectories and their contents


So I've seen a few posts that are similar to mine, but none of their answers seems to work for me.

I have a folder structure sort of like the following:

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

And I want to ignore everything except for the custom folders and the contents of them.

I have tried the following ignore file:

*
!.gitignore
!/custom/

and

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

But it ignores everything except for my root .gitignore file.

At least that is what it says when I run git status. And there are files under the custom/pages folders. So, what is it that I am missing?


Solution

  • Based on my testing the following should achieve the desired effect.

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