Search code examples
gitvivado

Git ignore everything in directories but one file type


I have this hierarchy, full of automatically generated folders:

| .gitignore
| ip
|   |ip1
|   |   |ip1.xci
|   |   |\other files\
|   |ip2
|   |   |ip2.xci
|   |   |\other files\
|   |ip3
|   |   |ip3.xci
|   |   |\other files\
|   |ip4
|   |   |ip4.xci
|   |   |\other files\
...

I want to write a rule to ignore everything but the .xci files (necessary to regenerate everything else), how do I write such a rule?

I have tried writing rules like:

ip/**/*
!ip/**/*.xci

but it doesn't work.

As I have understood it, git won't look for files in directories it has ignored even if the patter would match. Is there a way not to write a line for every file I want to keep? As other folders will be added.


Solution

  • You need to unignore directories to make git look into them:

    ip/**/*
    !ip/**/*/
    !ip/**/*.xci