![](/img/trans.png)
[英]git allow one directory while exclude rest folder in .gitignore fle
[英]Adding folder in ignored directory to git
我正在使用git version 2.17.1
。
我想忽略wp-content/uploads/*
和!wp-content/uploads/mailster/templates/sartre
到我的 git 存儲庫。
我使用腳本中的最后 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>
引用文檔:
第 4 段:
如果排除了該文件的父目錄,則無法重新包含該文件。
但是,即使它與.gitignore
模式匹配,您也可以使用git add -f
開始跟蹤它。
[更新]
有一種方法可以包含嵌套子目錄,方法是重復您已經在 .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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.