Gitignore glob path

I have this file hierarchy in my project:



I want to add rules to .gitignore so that all files inside assets are ignored except js files. I've tried following in .gitignore, which only considers script.js from the first level:



and then tried this, which also only takes script.js into account:



Other templates like! assets //. js or! assets / **. js doesn't work. I want all javascript files at all levels to be treated as unaffected.

I am trying to do this with Git version 2.1.0.


source to share

2 answers

You should not ignore any directories or look into those directories to include the .js

files underneath again. See What is the difference between Git ignoring the directory and the / * directory? ...

So, it .gitignore

should be:





files may already be tracked. please do not browse other files and add them to your ig

# Ignore everything
# Don't ignore directories, so we can recurse into them
# Don't ignore .gitignore and *.js files




All Articles