简体   繁体   中英

git ignore everything but some subdirectories

I need to control only "debian" subdirectories on my tree :

pkg/.git
pkg/.gitignore
pkg/package1/package1-2.2.1/debian
pkg/package2/package2-1.0/debian

I tried this kind of .gitignore but it won't work :

*
!.gitignore
!*/*/debian

When I run

git add package1/package1-2.2.1/debian

git's answer is : The following paths are ignored by one of your .gitignore files: package1

Which is quite logical. Any help would be appreciated !

You can still add it with:

git add -f package1/package1-2.2.1/debian

You probably don't want to ignore your .gitignore file, by the way, since you'll want to know when you have to commit any changes you've made to it. If you don't want the ignore rules to be committed in the repository, you should use .git/info/exclude instead.

As gitignore documentation says about prefix ! :

An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.

Maybe this means you can't use two consequent ! . Try to remove !.gitignore for a while and then run git add .

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