Gitignore除了一个文件夹及其所有内容

编程入门 行业动态 更新时间:2024-10-26 00:24:19
本文介绍了Gitignore除了一个文件夹及其所有内容 - 无论嵌套级别如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道这个问题已经被多次提出,但老实说 - 尽管有许多被接受的答案,但我还没有找到解决这个问题的简单方法。我在这里强调整洁。

我想忽略除一个文件夹及其整个内容以外的所有内容。 / p>

这不会实现它:

* ! dest !dest / *

将保留 dest 文件夹以及 dest 中的所有文件,但不包含in中的其他文件夹以及这些子文件夹中的文件。

有人在评论中写道!如果你使用 *开始你的 .gitignore ,那么如果没有指定你不想忽略的完整路径,你就无法实现这个问题。 。

我现在相信他是对的。或者有一种整洁的方式来忽略除一个文件夹及其整个内容之外的所有内容

解决方案 div>

我刚刚测试过(使用最近的Git,甚至在Windows上 )

* !dest / !dest / **

像往常一样,您只需遵循以下规则:

如果排除该文件的父目录,则无法重新包含文件。 ( * ) ( *

一旦 dest 文件夹被列入白名单(!dest / ),您可以轻松地(!dest / ** < code $)。

从那里,任何 git check-ignore -v dest / x / y / z / aFile 将不会返回任何内容,这意味着要添加 aFile 。

我提到了一个类似的原理解决方案)在 Gitignore排除所有子目录中的某些文件。

请注意,使用git 2.9.x / 2.10(2016年中期?),如果该文件的父目录被排除,那么可能会重新包含一个文件如果没有通配符路径重新包含。

NguyễnTháiNgọcDuy ( pclouds )正试图添加此功能: a gref =github/git/git/commit/506d8f1b394917c345965fc1762afa66678870c1 =nofollow noreferrer> commit 506d8f1 for git v2.7.0,在 commit 76b620d git v2.8.0-rc0

  • commit 5e57f9c git v2.8.0-rc0,...还原(!)在 commit 5cee3493 git 2.8.0-rc4。
  • 在这里,这应该适用于git 2.9 +:

    * !dest

    I know that this question has been asked many times, but honestly - in spite of many accepted answers, I've not found a neat solution to this problem. I stress the work neat here.

    I want to ignore everything except one folder and its entire contents.

    This will not achieve it:

    * !dest !dest/*

    that would preserve the dest folder and all files that are in dest, but not other folders within in as well as files in these sub-folders.

    Somebody wrote in comments! to one of similar questions that you cannot achieve this without specifying full paths to what you don't want to ignore if you start your .gitignore with *.

    I am now convinced that he was right. Or is there a neat way to ignore everything except one folder and its entire content

    解决方案

    I just tested (with a recent Git, even on Windows)

    * !dest/ !dest/**

    As usual, you just have to follow the rule:

    It is not possible to re-include a file if a parent directory of that file is excluded. (*) (*: unless certain conditions are met in git 2.?+, see below)

    Once the dest folder is white-listed (!dest/), you can exclude its content (on multiple levels) easily (!dest/**).

    From there, any git check-ignore -v dest/x/y/z/aFile would return nothing, which means aFile be added.

    I mentioned a similar principle (slightly different solution) in "Gitignore exclude certain files in all subdirectories".

    Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

    Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

    • commit 506d8f1 for git v2.7.0, reverted in commit 76b620d git v2.8.0-rc0
    • commit 5e57f9c git v2.8.0-rc0,... reverted(!) in commit 5cee3493 git 2.8.0-rc4.

    Here, this should work with git 2.9+:

    * !dest

    更多推荐

    Gitignore除了一个文件夹及其所有内容

    本文发布于:2023-11-24 05:23:13,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:所有内容   文件夹   Gitignore

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!