I am using git version 2.17.1
.
I would like to ignore wp-content/uploads/*
and !wp-content/uploads/mailster/templates/sartre
to my git repository.
I used the last 3 lines in the script to accomplish this.
However, the files do not get added to my repository.
Find below my *.gitignore
file:
*.log
wp-config.php
wp-content/advanced-cache.php
wp-content/backup-db/
wp-content/backups/
wp-content/blogs.dir/
wp-content/cache/
wp-content/upgrade/
wp-content/wp-cache-config.php
wp-content/plugins/hello.php
/.htaccess
/license.txt
/readme.html
/sitemap.xml
/sitemap.xml.gz
# Do not Ignore
package.json
acf-export-2019-11-15.json
# Ignore everything in the "wp-content" directory, except the "plugins",
# "themes" and "mu-plugins" directories.
wp-content/*
!wp-content/plugins/
!wp-content/mu-plugins/
!wp-content/themes/
!wp-content/uploads/
# Ignore everything in the root except the "wp-content" directory.
/*
!.gitignore
!wp-content/
# Ignore everything in the "plugins" directory, except the plugins you
# specify (see the commented-out examples for hints on how to do this.)
wp-content/plugins/*
!wp-content/mu-plugins
!wp-content/plugins/calendar
wp-content/plugins/calendar/vendor
wp-content/plugins/calendar/vendor/
# Ignore everything in the "themes" directory, except the themes you
# specify (see the commented-out example for a hint on how to do this.)
wp-content/themes/*
/wp-content/themes/twentynineteen/vendor/
!wp-content/themes/twentynineteen
# Ignore everything in the "uploads" directory, except the uploads you use
wp-content/uploads/*
!wp-content/uploads/mailster/templates/sartre
I appreciate your replies!
To debug gitignore issues : you can use git check-ignore -v <path>
Quoting the docs :
4th paragraph :
It is not possible to re-include a file if a parent directory of that file is excluded.
You can, however, use git add -f
to start tracking it even though it matches a .gitignore
pattern.
[update]
there is a way to include a nested subdirectory, by repeating the (*
/!
) pattern you already use in your .gitignore file :
wp-content/*
!wp-content/uploads
wp-content/uploads/*
!wp-content/uploads/mailster
wp-content/uploads/mailster/*
!wp-content/uploads/mailster/templates
wp-content/uploads/mailster/templates/*
!wp-content/uploads/mailster/templates/sartre
see also this SO answer