Pablo
Pablo

Reputation: 1435

Git Ignore for whole folder except for sub folder?

Currently I have this folder

/public/images

Where all images are being stored

But I have this 1 sub folder inside of images folder named as mycta

It is possible to ignore all files inside of /public/images

except for this directory /public/images/mycta?

As of now I have this /public/images in my gitignore file

Upvotes: 0

Views: 156

Answers (1)

rodrigo
rodrigo

Reputation: 98328

You can add a negative ignore pattern to your .gitignore file using a ! as follows:

.gitignore

/public/images/*
!/public/images/mycta

But note that instead of ignoring the whole parent directory you must ignore the contents, adding a * to that line, because as man gitignore says re !:

It is not possible to re-include a file if a parent directory of that file is excluded.

Upvotes: 2

Related Questions