Git忽略特定目录

3

我最近想要将我的dotnetnuke网站上传到git上,但是我的网站有大量图片,我不想通过git上传。

我在GIT上搜索时发现了.gitignore文件,并在创建仓库时自动生成,在GIT中有关于忽略文件/文件夹及其特定子文件夹的文档,但似乎在我的情况下无法使用。

这是我的文件夹结构:

*******已更新*******

.gitignore
public_html/Portals/_default/
public_html/Portals/0/
public_html/Portals/1/
public_html/Portals/110/

现在我想忽略除了Portals/_default之外的所有Portals文件夹。 我根据GIT的规范尝试了如下操作:
Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):

    $ cat .gitignore
    # exclude everything except directory foo/bar
    /*
    !/foo
    /foo/*
    !/foo/bar

以下是我尝试过的内容:
!/Portals
/Portals/*
!/Portals/_default

但是这似乎根本行不通。

有人能够指导我吗?


1
删除第一行,并删除前导斜杠(假设.gitignore文件与Portals文件夹相邻)。 - Plato
它为什么不按照你的意愿工作? - msw
@Plato:这个也不行,但是我已经更新了我的问题,展示了从根目录开始的完整目录结构。 - Abbas
1
你的问题似乎是public_html文件夹。将你的gitignore移动到public_html或在每一行中添加public_html文件夹。 - Johannes Thorn
1个回答

5

从gitignore的文档中可以看到:

例子:排除所有东西,除了一个特定的目录foo/bar(注意/* - 没有斜杠,通配符也会排除foo/bar内的所有内容):

$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*

太好了!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接