Git ignore except specific subdirectories

I've looked at some examples on how to ignore everything except certain sub directories like so.

# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/*

I have also tried:

# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/

UPDATE

So the code above works, however trying to exclude a directory within another directory within another does not work. It only works on the parent directory and sub directory.

# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/aaa/ddd/ 

After I include this in my gitingore, I run a git add --all and I dont see any the files in git status.

All help would be appreciated.

Answers


You have to unignore every directory in the path that you wish to unignore. Something like the following should work in your case:

# Ignore everything in foo
foo/*
# Except the ccc subdir
!foo/ccc

# Ignore everything in ccc subdir
foo/ccc/*
# Except the aaa subsubdir
!foo/ccc/aaa

# Ignore everything in aaa subsubdir
foo/ccc/aaa/*
# Except the ddd subsubsubdir
!foo/ccc/aaa/ddd

It's important that the ignore rules end in /*, as that tells git to ignore everything in the folder, but not the folder itself, permitting us to add exceptions to the ignore rules for specific subdirectories.


Need Your Help

Anybody successful with NSProxy of UIView (e.g., UILabel?)

iphone uiview uilabel calayer nsproxy

I am experimenting in adding functionality to my UIViews (configuring CALayers according to state) by setting up a NSProxy subclass to stand in for any UIView I choose. Here's what I've tried:

Python subprocess.call weird behavior with multiple calls

python subprocess

I am trying to call remote (ssh) commands using the subprocess.call function like this.