我知道这个问题已经被多次提出,但老实说 - 尽管有许多被接受的答案,但我还没有找到解决这个问题的简单方法。我在这里强调整洁。
我想忽略除一个文件夹及其整个内容以外的所有内容。 / 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
在这里,这应该适用于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除了一个文件夹及其所有内容
发布评论