.gitignore 排除文件夹但包含特定的子文件夹 [英] .gitignore exclude folder but include specific subfolder

查看:60
本文介绍了.gitignore 排除文件夹但包含特定的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文件夹 application/,我将它添加到 .gitignore.application/ 文件夹内是文件夹 application/language/gr.如何包含此文件夹?

I have the folder application/ which I add to the .gitignore. Inside the application/ folder is the folder application/language/gr. How can I include this folder?

我已经试过了

application/
!application/language/gr/

没有运气...

推荐答案

如果您排除 application/,那么它下面的所有内容都将始终被排除(即使某些后来的否定排除模式(unignore")) 可能与 application/ 下的内容匹配.

If you exclude application/, then everything under it will always be excluded (even if some later negative exclusion pattern ("unignore") might match something under application/).

为了做你想做的事,你必须忽略"你想要忽略"的任何东西的每个父目录.通常你最终会成对地为这种情况编写规则:忽略目录中的所有内容,但不忽略某些特定的子目录.

To do what you want, you have to "unignore" every parent directory of anything that you want to "unignore". Usually you end up writing rules for this situation in pairs: ignore everything in a directory, but not some certain subdirectory.

# you can skip this first one if it is not already excluded by prior patterns
!application/

application/*
!application/language/

application/language/*
!application/language/gr/

注意
尾随的 /* 很重要:

  • 模式 dir/ 排除了一个名为 dir 的目录以及(隐式地)它下的所有内容.
    使用 dir/,Git 永远不会查看 dir 下的任何内容,因此永远不会将任何取消排除"模式应用于 dir.
  • 模式dir/* 没有说明dir 本身;它只是排除 dir 下的所有内容.使用 dir/*,Git 将处理 dir 的直接内容,让其他模式有机会取消排除"某些内容(!dir/sub/).
  • The pattern dir/ excludes a directory named dir and (implicitly) everything under it.
    With dir/, Git will never look at anything under dir, and thus will never apply any of the "un-exclude" patterns to anything under dir.
  • The pattern dir/* says nothing about dir itself; it just excludes everything under dir. With dir/*, Git will process the direct contents of dir, giving other patterns a chance to "un-exclude" some bit of the content (!dir/sub/).

这篇关于.gitignore 排除文件夹但包含特定的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆