gpt4 book ai didi

git - Git中忽略目录的Unignore子目录

转载 作者:IT王子 更新时间:2023-10-29 00:32:36 26 4
gpt4 key购买 nike

假设我忽略了一个目录,但我想取消忽略其中的特定子目录。所以我有设置:

/uploads/
/uploads/rubbish/
/uploads/rubbish/stuff/KEEP_ME/
/uploads/foo/
/uploads/foo/bar/lose/

我想忽略除 KEEP_ME 目录之外的所有内容。我希望忽略看起来像:

/uploads/*
!/uploads/rubbish/stuff/KEEP_ME/

但这行不通,同一主题的多个排列也行不通。

一个有效的是

/uploads/**/**/**/
!/uploads/rubbish/stuff/KEEP_ME/

但这感觉有点局限和冗长?

最佳答案

根据 pattern format section of the gitignore documentation :

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".

因此,先前排除的父目录 /uploads/rubbish/stuff/keep/ 模式必须在否定其内容之前完全否定:

#ignore everything within /uploads/ 
/uploads/*

#include everything within /uploads/rubbish/stuff/keep
!/uploads/rubbish/stuff/keep/
!/uploads/rubbish/stuff/keep/*

要在 /uploads/rubbish/stuff/keep/ 中包含子目录,请添加第三行:

!/uploads/rubbish/stuff/keep/**/*

关于git - Git中忽略目录的Unignore子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5261959/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com