简体   繁体   中英

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.

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

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

There is .gitignore file associated with every git repository if not just create one.

You can Ignore directories by entering the directory name into the file (with a slash appended):

dir_to_ignore/

More information is here .

You can mention all what you want to ignore there as extension as well for files

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