简体   繁体   中英

Ignore a directory except specific files in a subdirectory in Git

So, I've tried this with several approaches, but only this one works:

/*
!/dev/
/dev/*
!/dev/host/
/dev/host/*
!/dev/host/mail/
/dev/host/mail/*
!/dev/host/mail/htdocs/
/dev/host/mail/htdocs/*
!/dev/host/mail/htdocs/install/

What I want is to ignore all files, except inside /dev/host/mail/htdocs/install/. So all other files should be ignored entirely, except the ones inside the mentioned sub-folder.

I've tried this, but it doesn't work:

/*
!/dev/host/mail/htdocs/install/

Any idea how to shrink down the mess above? Do I really need as many lines as above; two lines for every directory level?

Am I missing something? Thanks a lot!

Allowing everything under install after ignoring everything else ( * ) has the form

*
!/dev
!/dev/host
!/dev/host/mail
!/dev/host/mail/htdocs
!/dev/host/mail/htdocs/install
!/dev/host/mail/htdocs/install/*

But this also allows stray files at higher levels of the tree. That means adding the additional ignore rules from your question.

The short answer is what you have is necessary. It is an odd repository structure, so git does not optimize for it.

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