简体   繁体   中英

Git: Ignore Subfolder of All Folders Except One

currenty I have an repository that looks like this:

Git-Repository
└─── A
│  └─── X
│  └─── Y
└─── B
│  └─── X
│  └─── Y
└─── C
│  └─── X
│  └─── Y
│ ....

I want to edit my .gitignore file to somehow ignore all X subdirectories except the one in C directory.

It is important to mention that this is a simple version of my real repo. I actually have a LOT more folders and subfolders, so I cant set all the directories one by one.

Edit1: This is what I am trying to do, but not working. X subdirectory is being correcyly ignored, but the one in "C" isnt ""unignored""

X/
!C/X/*

From the gitignore docs .

If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself.

That means X/ will only match a top level X directory.

To match subdirectories, use a wildcard.

*/X/
!C/X/

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