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

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

问题描述

我有添加到.gitignore的文件夹应用程序。应用程序/文件夹内部是文件夹应用程序/语言/ gr。我怎样才能包含这个文件夹?
我试过了这个应用程序/ language / gr /


  application / 

没有运气......

解决方案

如果您排除 application / ,那么它下面的所有内容都将被排除(即使稍后的否定排除模式(unignore)可能与 application / )。



要做你想做的事情,你必须你想要统一。通常你最终会为这种情况成对编写规则:忽略目录中的所有内容,但不包括某些特定的子目录。

 #you可以跳过这第一个,如果它没有被先前模式排除的话
!application /

application / *
!application / language /

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


$ b $ ul

  • 模式dir /不包括名为dir的目录和(隐式地)
    使用dir /,Git将永远不会查看dir下的任何内容,因此绝不会将任何un-exclude模式应用于dir下的任何内容。

  • 模式dir / *没有提到dir本身;它只是排除了dir下的所有内容。
    使用dir / *,Git将处理目录的直接内容,为其他模式提供解除某些内容(!dir / sub /)的机会。


  • 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? I've tried this

    application/
    !application/language/gr/
    

    with no luck...

    解决方案

    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/
    

    Note
    The trailing /* is significant:

    • 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天全站免登陆