简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM