简体   繁体   中英

gitignore: Ignore everything from subfolder except files with specific extensions

I'm a bit overwhelmed with the amount of gitignore related questions on stackoverflow, but couldn't find one with the same problem I currently have:

This is my file structure:

➜  main git:(master) ✗ tree
.
└── lib
    ├── folder1
    │   ├── sub1
    │   │   └── test.txt
    │   ├── test.md
    │   └── test.txt
    └── folder2
        ├── sub1
        │   └── test.txt
        ├── test.md
        └── test.txt

5 directories, 6 files

I would like to exclude the lib folder, but include every file with the extension ".txt".

This is my current.gitignore file:

➜  main git:(master) ✗ cat .gitignore
/lib/
!/lib/**/*.txt

Unfortunately, the whole lib folder is excluded and no textfile is included.

I also have tried countless of other patterns, but I end up either with the lib folder being ignored by git or a lib folder which is being included with all of its files.

It's also important to me that I don't have to specify each subfolder in my.gitignore (like !folder1/ , !folder2/ ).

Following works:

lib/**/*.*
!lib/**/*.txt

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