我正在使用git version 2.17.1。
我想忽略git存储库中的wp-content/uploads/*和!wp-content/uploads/mailster/templates/sartre。
我使用脚本中的最后3行来完成这个任务。
但是,这些文件不会添加到我的存储库中。
请在我的*.gitignore文件下面找到:
*.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谢谢你的回复!
发布于 2020-10-22 19:53:19
要调试gitignore问题:可以使用git check-ignore -v <path>
引用医生们:
第4段: 如果排除该文件的父目录,则不可能重新包含该文件。
但是,您可以使用git add -f开始跟踪它,即使它与.gitignore模式匹配。
更新
有一种方法可以包含嵌套子目录,方法是重复已经在您的*文件中使用的(!/ .gitignore )模式:
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另见这就是答案
https://stackoverflow.com/questions/64488439
复制相似问题