Falken
Falken

Reputation: 2568

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 !

Upvotes: 5

Views: 474

Answers (2)

beduin
beduin

Reputation: 8253

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.

Upvotes: -1

Mark Longair
Mark Longair

Reputation: 467033

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.

Upvotes: 2

Related Questions