git忽略特定类型的所有文件,除了特定子文件夹中的文件 [英] git ignore all files of a certain type, except those in a specific subfolder

查看:713
本文介绍了git忽略特定类型的所有文件,除了特定子文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的目录结构:


  • root

    • folder1

      • abc.json
      • def.json
      • somedir

        • more.json



    • folder2

      • qwe.json

      • rty.json



      • mock1.json
      • mock2.json

      • somedir

        • more_mocks.json





    现在使用 .gitignore 我想忽略所有 *。 json 文件,除了 spec 中的文件外。我不想在 folder1 folder2 .gitignore $ c>因为有很多这样的东西,他们会被添加到很多,我确信我会忘记将正确的 .gitignore 文件移到原地。



    另外,使用json文件可能会有更多的嵌套目录,并且此规则也需要应用于所有子目录。



    那么如何忽略一个类型的所有文件,除了某个子目录?

    一个可选的前缀,它抵消了
    模式;
    排除的任何匹配文件将重新包含在
    中。如果一个否定模式
    匹配,这将覆盖较低
    优先模式的源。


    http://schacon.github.com/git/gitignore.html

      *。json 
    !spec / *。json


    I have a directory structure like this:

    • root
      • folder1
        • abc.json
        • def.json
        • somedir
          • more.json
      • folder2
        • qwe.json
        • rty.json
      • spec
        • mock1.json
        • mock2.json
        • somedir
          • more_mocks.json

    Now using a .gitignore I want to ignore all *.json files except for the ones in the spec. I don't want to use a .gitignore in folder1 and folder2 because there are a ton of these and they will get added to a lot, and i'm sure I will forget to move the right .gitignore file in place.

    In addition there may be more nested directories with json files, and this rule needs to apply to all subdirectories as well.

    So how do I ignore all files of a type, except for a certain subdirectory?

    解决方案

    An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.

    http://schacon.github.com/git/gitignore.html

    *.json
    !spec/*.json
    

    这篇关于git忽略特定类型的所有文件,除了特定子文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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