本文介绍了在Git中取消忽略忽略目录的子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  / uploads / 
/ uploads /垃圾/
/ uploads /垃圾/ stuff / KEEP_ME /
/ uploads / foo /
/ uploads / foo / bar / lose /

我想忽略所有内容,但 KEEP_ME 目录。我希望这个忽略看起来像这样:

  / uploads / * 
!/ uploads /垃圾/ stuff / KEEP_ME /

但这并不奏效,在同一个主题上也没有多少变化。



其中一项工作是

  / uploads / ** / ** / * * / 
!/ uploads /垃圾/ stuff / KEEP_ME /

限制性的和详细的?

解决方案

据:

之前排除的父目录 / uploads /垃圾/ stuff / keep / 模式必须在否定其内容之前完全否定:

  #ignore所有内容/ uploads / 
/ uploads / *

#include everything / within / uploads / garbage / stuff / keep
!/ uploads /垃圾/ stuff / keep /
!/ uploads /垃圾/ stuff / keep / *

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

 !/ uploads /垃圾/ stuff / keep / ** / * 


Let's say I have ignored a directory, but I want to unignore specific subdirectories therein. So I have the setup:

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

And I want to ignore everything but the KEEP_ME directory. I would hope the ignore would look something like:

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

But that's not working, and neither are several permutations on the same theme.

One that does work is

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

But that feels a little restrictive and verbose?

解决方案

According to pattern format section of the gitignore documentation:

Therefore the previously-excluded parent directory /uploads/rubbish/stuff/keep/ pattern must be exclusively negated before negating its content:

#ignore everything within /uploads/
/uploads/*

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

To include subdirectories inside /uploads/rubbish/stuff/keep/ add the third line:

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

这篇关于在Git中取消忽略忽略目录的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:49