2

我有以下目录结构:

/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

我想忽略我的存储库中的所有文件,除了/src/MyProject/SecondProject/Resources. 我尝试了很多方法,但没有成功。GitHub 应用程序没有检测到我想要的目录。通常这个应用程序不会检测到任何文件或检测到所有文件,所以我很困惑。

我试过了:

# 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/**/*

我还没有在其他问题中找到解决方案!

4

1 回答 1

2

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
于 2016-02-11T06:12:50.010 回答