将忽略目录中的文件夹添加到 git

Adding folder in ignored directory to git

我正在使用 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

感谢您的回复!

要调试 gitignore 问题:您可以使用 git check-ignore -v <path>

引用 the docs :

4th paragraph :

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

但是,即使它匹配 .gitignore 模式,您也可以使用 git add -f 开始跟踪它。