title: Correctly ignore all files recursively under a specific folder except for a specific file type
body: <p>I have seen similar questions (<a href="https://stackoverflow.com/questions/11852558/gitignore-only-allow-certain-extensions-and-files">1</a>, <a href="https://stackoverflow.com/questions/9049835/how-can-i-ignore-all-files-except-those-with-a-certain-extension-in-git">2</a> and <a href="https://stackoverflow.com/questions/8024924/gitignore-ignore-all-files-then-recursively-allow-foo">3</a>), but I don't get a proper solution from them. </p>
  
  <p>I need to ignore all files under a particular folder except for a specific file type. The folder is a subdirectory for the root path. Let me name the folder <code>Resources</code>. Since I don't want to complicate things, let me ignore files under all folders named <strong><code>Resources</code></strong> wherever it is.</p>
  
  <p>This is the most common solution (in all the duplicate questions)</p>
  
  <pre><code># Ignore everything
  *
  
  # Don't ignore directories, so we can recurse into them
  !*/
  
  # Don't ignore .gitignore
  !.gitignore
  
  # Now exclude our type
  !*.foo
  </code></pre>
  
  <p>The problem with this solution is that <strong>it stops tracking newly added files</strong> (since <code>*</code> ignores all files). I don't want to keep excluding each and every file type. I want normal behaviour where if any new file is added, <code>git status</code> shows it. </p>
  
  <p>I finally got a solution <a href="https://stackoverflow.com/questions/7803689/gitignore-ignore-all-files-in-folder-hierachy-except-one-specific-filetype">here</a>. The solution is to add another <code>.gitignore</code> file in <code>Resources</code> folder. This works correctly. </p>
  
  <p>Can I achieve the same with one ignore file? I find having many ignore files in different directories a bit clunky.</p>
  
  <p>This is what I'm trying to achieve: </p>
  
  <pre><code># Ignore everything under Resources folder, not elsewhere
  Resources
  
  # Don't ignore directories, so we can recurse into them
  !*Resources/
  
  # Now exclude our type
  !*.foo
  </code></pre>
  
  <p>But this gives the opposite output. It ignores <code>*.foo</code> types and tracks other files.</p>