繁体   English   中英

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

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

我当前的目录树看起来像:

.
├── 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

我想忽略除test1目录下的.json文件之外的所有内容。

我的.gitignore文件如下所示:

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

我的git status -sb output 是:

## No commits yet on master
?? .gitignore

因此,它没有跟踪test1目录下的.json文件。

这里的解决方案可能是什么?

您可以将以下行添加到您的.gitignore文件中:

# ignore all files
**/*.*

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

还有一个不错的帖子,您可以在其中找到解决方案的基础知识。

仅尝试在 .gitignore 文件中的这一行

test1/.*.json

暂无
暂无

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

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