首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将忽略目录中的文件夹添加到git中

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

Stack Overflow用户
提问于 2020-10-22 18:29:46
回答 1查看 285关注 0票数 1

我正在使用git version 2.17.1

我想忽略git存储库中的wp-content/uploads/*!wp-content/uploads/mailster/templates/sartre

我使用脚本中的最后3行来完成这个任务。

但是,这些文件不会添加到我的存储库中。

请在我的*.gitignore文件下面找到:

代码语言:javascript
复制
*.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

谢谢你的回复!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-22 19:53:19

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

引用医生们

第4段: 如果排除该文件的父目录,则不可能重新包含该文件。

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

更新

有一种方法可以包含嵌套子目录,方法是重复已经在您的*文件中使用的(!/ .gitignore )模式:

代码语言:javascript
复制
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

另见这就是答案

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64488439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档