title: Git ignore all files of a certain type except in all subdirectories of a certain directory?
body: <p>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:</p>
  
  <pre><code>-.gitignore 
  -libs/
      -goodFile.jar
      -someFolder/
          -subFolder/
              -alsoGood.jar
  -otherCode/
      -fileToExclude.jar
  -otherOtherCode/
      -otherSubfolder/
          -alsoExclude.jar
  </code></pre>
  
  <p>Currently in .gitignore I've tried:</p>
  
  <pre><code>*.jar
  !libs
  !libs/
  !libs/*
  !libs/**
  !libs/**/
  !libs/**/*.jar
  !libs/*.jar
  </code></pre>
  
  <p>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 <code>libs/</code> (which I would prefer to avoid) or use a <code>!libs/*/*/*.jar</code> line for every possible level of subdirectory. Is there a way to make it ignore all jars except the ones in libs?</p>