简体   繁体   中英

Ignore all files except in subfolder

I have a git repo with many files and folder but I want to ignore everything except files and folders in a src folder.

This is my .gitignore:

/*

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

But this is what git status 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)

So it seems that it is ignoring everything including my src folders.

Make sure to ignore files only, not folders:

*
!*/

It is not possible to re-include a file if a parent directory of that file is excluded (even with 2.7 in your case)

Then you can exclude the folder src files and subfolders content:

!**/src/**

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM