neotohin
neotohin

Reputation: 163

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 in .gitignore so that all files inside assets gets ignored except js files. I tried following in .gitignore that only considers script.js from first level:

assets
!assets/*.js

and then tried this which too only considers script.js :

assets
!assets/**/*.js

Other patterns like !assets//.js or !assets/**.js does not works. I want to consider all javascript files in all levels to consider as untracked.

I am trying this with Git version 2.1.0 .

Upvotes: 3

Views: 1418

Answers (2)

Landys
Landys

Reputation: 7747

You should not ignore any directories or it will not look into these directories to include .js files under them again. Refer to What's the difference between Git ignoring directory and directory/*?.

So the .gitignore should be:

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

Upvotes: 4

g-newa
g-newa

Reputation: 469

may be files are already tracked. please untrack other files and add it to your ig

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

Upvotes: 0

Related Questions