忽略除子文件夹中的所有文件

Ignore all files except in subfolder

我有一个包含许多文件和文件夹的 git 存储库,但我想忽略除 src 文件夹中的文件和文件夹之外的所有内容。

这是我的。git忽略:

/*

!**/src/
!.gitignore
!README.md

但这就是git状态 returns:

$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        README.md

nothing added to commit but untracked files present (use "git add" to track)

所以它似乎忽略了所有内容,包括我的 src 文件夹。

确保只忽略文件,而不是文件夹:

*
!*/

It is not possible to re-include a file if a parent directory of that file is excluded(即使你的情况是 2.7)

然后你可以排除文件夹src文件和子文件夹内容:

!**/src/**