简体   繁体   English

gitignore 特定目录的所有子目录中除 .json 文件之外的所有文件

[英]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.我想忽略除test1目录下的.json文件之外的所有内容。

my .gitignore file looks like:我的.gitignore文件如下所示:

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

my git status -sb output is:我的git status -sb output 是:

## No commits yet on master
?? .gitignore

So, it is not tracking the .json files under test1 directory.因此,它没有跟踪test1目录下的.json文件。

What might be the solution here?这里的解决方案可能是什么?

You can add the following lines to your .gitignore file:您可以将以下行添加到您的.gitignore文件中:

# 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仅尝试在 .gitignore 文件中的这一行

test1/.*.json test1/.*.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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