Home > Blockchain >  Git: Ignore Subfolder of All Folders Except One
Git: Ignore Subfolder of All Folders Except One

Time:07-05

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/*

CodePudding user response:

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/
  • Related