忽略.gitignore中除一个目录以外的所有内容 [英] Ignore everything except one directory in .gitignore
问题描述
/ app
/ src
/ MyProject
/ FirstProject
/控制器
/file-1-1.php
/file-1-2.php
/file-1-3.php
/资源
/view-1.html.twig
/view-2.html.twig
/ SecondProject
/控制器
/file-2-1.php
/file-2-2.php
/file-2-3.php
/资源
/view-3.html.twig
/ view-4 .html.twig
/ vendor
/ web
我想<除了 / src / MyProject / SecondProject / Resources
中的文件外,在我的存储库中忽略所有文件。
我尝试过很多方法,但没有成功。 GitHub应用程序不检测我想要的目录。通常这个应用程序不检测任何文件或检测到所有文件,所以我很困惑。
我试过了:
#IGNORE:
app /
src /
供应商/
网站/
#允许:
#我的第一次尝试:
!src / MyProject / SecondProject / Resources / *
#第二次尝试:
!src / MyProject / SecondProject / Resources / ** /
#third尝试:
!src / MyProject / SecondProject / Resources / ** / *
我还没有在其他问题中找到解决方案!
/ app
/ vendor
/ web
/ src / ** / **
!src / ** /
!/ src / MyProject / SecondProject / Resources / **
mipadi 的 answer 指的是2.7.1版本中引入的机制,并且在2.7.1中颠倒过来!
剩下的唯一规则是:
因此,
在白名单 Resources
内容之前,需要白名单 src
子文件夹。
我测试了上面的内容:
> git --version
git version 2.7.1.windows.1
I have the following directory structure:
/app
/src
/MyProject
/FirstProject
/Controller
/file-1-1.php
/file-1-2.php
/file-1-3.php
/Resources
/view-1.html.twig
/view-2.html.twig
/SecondProject
/Controller
/file-2-1.php
/file-2-2.php
/file-2-3.php
/Resources
/view-3.html.twig
/view-4.html.twig
/vendor
/web
I would like to ignore all files in my repository except files in /src/MyProject/SecondProject/Resources
.
I have tried many ways but without success. GitHub application does not detect a directories that I want. Usually this application does not detect any file or detects all, so I am confused.
I tried:
# IGNORE:
app/
src/
vendor/
web/
# ALLOW:
# my first attempt:
!src/MyProject/SecondProject/Resources/*
# second attempt:
!src/MyProject/SecondProject/Resources/**/
# third attempt:
!src/MyProject/SecondProject/Resources/**/*
I haven't found a solution in an other questions!
This .gitignore
will actually work:
/app
/vendor
/web
/src/**/**
!src/**/
!/src/MyProject/SecondProject/Resources/**
mipadi's answer refers to a mechanism introduced in git 2.7.0 and... reversed in 2.7.1!
The only rule left is:
It is not possible to re-include a file if a parent directory of that file is excluded.
Hence the need for white-listing src
sub-folders, before white-listing Resources
content.
I tested the above with:
> git --version
git version 2.7.1.windows.1
这篇关于忽略.gitignore中除一个目录以外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!