Gitignore glob path

I have this file hierarchy in my project:

assets
  --script.js
  --a.html
  --admin
    --carousel.js
    --documentation.html

      

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:

assets
!assets/*.js

      

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

assets
!assets/**/*.js

      

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.

+3


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:



assets/**
!assets/**/
!assets/**/*.js

      

+3


source


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
!.gitignore
!*.js

      

0


source







All Articles