-2

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/*
Miguel
  • 157
  • 1
  • 11
  • Does this answer your question? [git ignore all files except one extension and folder structure](https://stackoverflow.com/questions/24677866/git-ignore-all-files-except-one-extension-and-folder-structure) – Schwern Jun 30 '22 at 22:18
  • @Schwern I have tried it but it is not working – Miguel Jun 30 '22 at 22:32
  • @Miguel Have any files in those directories already been committed? – Schwern Jul 02 '22 at 17:43
  • @Schwern not yet. Still trying to make the "unignore" part to work – Miguel Jul 04 '22 at 14:57

1 Answers1

1

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/
Schwern
  • 153,029
  • 25
  • 195
  • 336
  • Still not working properly... "X" was beeing ignored in both ways, but the on in "C" directory isnt being """unignored""" – Miguel Jul 04 '22 at 14:53
  • @Miguel Works For Me™. We'd need more information. – Schwern Jul 04 '22 at 18:48
  • Just realized that I was addind an extra star (*) at the end of the "unignore" command. Removing it solve the problem – Miguel Jul 05 '22 at 00:06