Git-忽略存储库内任何位置的任何文件夹,该文件夹以递归方式允许所有操作 [英] Git - Unignore any folder located anywhere inside repository that recursively allows everything

查看:118
本文介绍了Git-忽略存储库内任何位置的任何文件夹,该文件夹以递归方式允许所有操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何取消忽略具有特定名称(例如Sync)的文件夹,该文件夹可以位于存储库内的任何位置,并以递归方式允许其中的所有内容,从而违反gitignore的所有其他规则?

How to unignore folder with a particular name (e.g. Sync) that can be located anywhere inside the repository and Recursively allow everything inside it, violating every other rule of gitignore?

推荐答案

提议的解决方案(!/**/Sync/**/*)不能单独使用,因为 如果排除了该文件的父目录,则无法重新添加该文件.

The solution proposed (!/**/Sync/**/*) would not work alone, because It is not possible to re-include a file if a parent directory of that file is excluded.

因此,如果您的.gitignore具有:

*
!.gitignore

您必须先将文件夹列入白名单(!*/),然后再排除文件(!**/Sync/**,不需要**/*)

You must whitelist folders first (!*/) and then exclude files (!**/Sync/**, no need for **/*)

最终结果将为.gitignore,如:

*
!.gitignore
!*/
!**/Sync/**

别忘了检查适用.gitignore规则的任何文件:

Don't forget to check with any file which .gitignore rule applies with:

git check-ignore -v -- aFile

注意:(!**/Sync/**)需要/(如果要从存储库的 top 锚定白名单).
如果不是,则不需要/:这与您的.gitignore所在的位置有关.

Note: / would be needed (for !**/Sync/**) if you wanted to anchor the whitelist from the top of your repository.
If not, no / needed: this would be relative to wherever your .gitignore is).

来自 gitignore手册页:

如果该模式不包含斜线/,则Git会将其视为shell glob模式,并检查相对于.gitignore文件位置的路径名是否匹配(相对于工作树的顶层) (如果不是来自.gitignore文件).

If the pattern does not contain a slash /, Git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).

这篇关于Git-忽略存储库内任何位置的任何文件夹,该文件夹以递归方式允许所有操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆