Git会忽略某个目录的所有子目录中的某种类型的所有文件吗? [英] Git ignore all files of a certain type except in all subdirectories of a certain directory?

查看:72
本文介绍了Git会忽略某个目录的所有子目录中的某种类型的所有文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个gitignore文件,该文件将忽略所有.jar文件,除非它们位于名为libs的文件夹中.这是我的基本文件结构:

I'm trying to make a gitignore file that will ignore all .jar files unless they're in a folder called libs. Here's my basic file structure:

-.gitignore 
-libs/
    -goodFile.jar
    -someFolder/
        -subFolder/
            -alsoGood.jar
-otherCode/
    -fileToExclude.jar
-otherOtherCode/
    -otherSubfolder/
        -alsoExclude.jar

目前在.gitignore中,我已经尝试过:

Currently in .gitignore I've tried:

*.jar
!libs
!libs/
!libs/*
!libs/**
!libs/**/
!libs/**/*.jar
!libs/*.jar

可以单独,组合甚至一起使用.他们都不工作.我发现做到这一点的唯一方法是将另一个.gitignore文件放入 libs/(我希望避免)或使用!libs/*/*/* .jar 行用于子目录的每个可能级别.有没有办法让它忽略除libs中的罐子以外的所有罐子?

Either on their own, in combination, or even all together. None of them work. The only way I've found to do it is to either put in another .gitignore file into libs/ (which I would prefer to avoid) or use a !libs/*/*/*.jar line for every possible level of subdirectory. Is there a way to make it ignore all jars except the ones in libs?

推荐答案

怎么样:

*.jar
!libs/**/*.jar

顺序很重要.

修改在执行 git add git status

$ git stat
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   .gitignore
    new file:   libs/goodFile.jar
    new file:   libs/someFolder/subFolder/alsoGood.jar
    new file:   libs/someFolder/subFolder/test/anotherFolder/test.jar



$ cat .gitignore 
*.jar
!libs/**/*.jar

这篇关于Git会忽略某个目录的所有子目录中的某种类型的所有文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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