Git ignore list of all files in subdirectory, recursively

My software project is modular. Some files are committed by the developer in designated subdirectories, others are uncompressed to provide a runtime environment (web resources) for development and do not need to be executed.

- webapp
   - common (provided)
   - error (provided)
   - secure
      - admin (provided)
      - audit (provided)
      - ftt (provided)
   - WEB-INF (to ignore)


I want to ignore everything under webapp except all files in /webapp/secure/ftt

and its subdirectories.

I tried



But Git still ignores ftt.

I expect these directories to contain only files .jsp

and .js

. But I cannot know what will happen in the future (like gif, pdf, etc.)

How can I tell Git to whitelist in /webapp/secure/ftt

and ignore everything else in /webapp


From my research, I've found that this is not possible without listing each specific subdirectory and file template.

[Add] after @DevDonkey comment I tried to clean up the whole gitignore file and leave what it posted



Along with a lot of useless files (like .class files) that are now candidates for indexing, since as I said I emptied gitignore, I believe that sample.jsp is still being ignored

See yourself


source to share

2 answers

What about



works for me locally. Note the addition of the forward slash and wildcard, so git keeps the root folder but then processes the rest.



You should do some inelegant solution like expanding a single file .gitignore

into a directory /webapp/secure/ftt

based on the following:

# Ignore any file in this directory except for this file and *.foo files


If you don't want or can't add this .gitignore file, there is an inelegant solution:

# Ignore any file but *.foo under Resources. Update this if we add deeper directories




All Articles