1

I am working with Grav CMS with this folder structure (simplified):

/user/
  /pages/
  /plugins/
    /admin/
    /devtools/
    /google-photos/
    .gitkeep

and this .gitignore file:

/user/plugins
!.gitkeep
!/user/plugins/google-photos/

I want to ignore all files and folders (with subfolders) in /user/plugins except all .gitkeep files. This works so far. But now I would like to include a single plugin in git (google-photos) with all its content. I tried this, but it didn't work: !/user/plugins/google-photos/

How can I do this?

I already visited these, but they couldn't help:

chraebsli
  • 184
  • 12

1 Answers1

1

If /user/plugins folder is ignored, then any exception below that folder will be ignored.

That is because:

The general rule is:

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

To exclude files/folders from /user/plugins (whose content is ignored), you would do:

/user/plugins/*
!/user/plugins/.gitkeep
!/user/plugins/google-photos/

Meaning: you need to whitelist folders first, before being able to exclude from gitignore files.

Double-check with git check-ignore -v -- path/to/file to confirm it is working as expected

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • now that your question is edited, this remaining comment could be misleading. perhaps delete it completely? – LeGEC Apr 29 '23 at 04:22