如何忽略文件夹中不以@开头的所有目录?

How to ignore all directories in a folder that don't begin with @?

在我的项目中,我有一个 src/apps/ 目录。我希望 git 忽略所有不以 @ 符号开头的子目录(保留 src/apps/@dir/src/apps/文件).

package.json
    |
.gitignore
    |
   src/ - - -
            |
          apps/ - - -
                    |
              keep-this-file
                    |
              keep-this-file-too
                    |
              @keep-this-dir/
                    |
              @keep-this-dir-too/
                    |
              ignore-this-dir/
                    |
              ignore-this-dir-too/

.gitignore 文件还可以为忽略的文件定义排除项:

src/apps/*/
!src/apps/@*/

这将忽略 src/apps 目录中的所有文件,但该目录中以 @.

开头的所有文件除外