1

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?

Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87

2 Answers2

4

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.

flaxel
  • 4,173
  • 4
  • 17
  • 30
0

Try only this line in .gitignore file

test1/!*.json

oda
  • 46
  • 3