简体   繁体   中英

gitignore all files except the .json files in all subdirectories of a particular directory

my current directory tree looks like:

.
├── test1
│   ├── test.docx
│   ├── test.jpg
│   ├── test.json
│   ├── test2
│   │   ├── test.docx
│   │   ├── test.jpg
│   │   ├── test.json
│   │   └── test4
│   │       ├── test.docx
│   │       ├── test.jpg
│   │       └── test.json
│   └── test3
│       ├── test.docx
│       ├── test.jpg
│       └── test.json
└── test5
    ├── test.docx
    ├── test.jpg
    ├── test.json
    ├── test2
    │   ├── test.docx
    │   ├── test.jpg
    │   ├── test.json
    │   └── test4
    │       ├── test.docx
    │       ├── test.jpg
    │       └── test.json
    └── test3
        ├── test.docx
        ├── test.jpg
        └── test.json

I want to ignore everything except .json files which are under test1 directory.

my .gitignore file looks like:

/*
!/.gitignore
!/test1
/test1/**/*.json

my git status -sb output is:

## No commits yet on master
?? .gitignore

So, it is not tracking the .json files under test1 directory.

What might be the solution here?

You can add the following lines to your .gitignore file:

# ignore all files
**/*.*

# except json files in test1 folder
!test1/**/*.json

There is also a nice post where you can find the basic for the solution.

Try only this line in.gitignore file

test1/.*.json

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