Vishal Zanzrukia
Vishal Zanzrukia

Reputation: 4973

gitignore file pattern not working

I have dynamic directory structure like,

dependency
  a
    b
  c
    d  e
  f
    g
      h

I want to ignore all files under dependency folder recursively except .xml files.

I am using below pattern to achieve the same.

dependencies/**
!dependencies/**/*.xml

But it seems it's not working for me. It's ignoring all the files but accepting only .xml files which are directly inside the dependency folder, not recursively. :(

I am using below environment.
OS : Windows 7(64 bit)
Git : 2.6.1.windows.1

Can anyone help me?

Upvotes: 1

Views: 524

Answers (1)

VonC
VonC

Reputation: 1326666

This should work:

You ignore everything but white-list the parent folders.
Then you can white-list files.

dependencies
!dependencies/**/
!dependencies/**/*.xml

As I mentioned in "How do I add files without dots in them (all extension-less files) to the gitignore file?", there is mainly one rule to remember with .gitignore:

It is not possible to re-include a file if a parent directory of that file is excluded.

That means, when you exclude everything ('*'), you have to white-list folders, before being able to white-list files.

Check if this is working with git check-ignore -v -- afile to see if it is ignored (and by which rule) or not.

Upvotes: 1

Related Questions