1

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?

Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82
  • got root cause behind this, there are certain rules while **excluding** or **re-including** files. Refer : http://git-scm.com/docs/gitignore#_notes – Vishal Zanzrukia Jan 28 '16 at 06:34

1 Answers1

1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250