Git ignore everything except subfolder

I was looking for other questions, but could not find a working solution for my project. Having a Magento project, I want to exclude everything except this:

/app/design/frontend/default/theme_name # and obviously all subfolders /skin/frontend/default/theme_name # and all subfolders 

I tried many combinations, but no luck. I am currently stuck in this .gitignore file:

 * !/app/ !/app/* app/* !/app/design/ !/app/design/* 

But it does not work recursively under the design folder. He just added a test file inside the folder I created.

+7
git gitignore magento
source share
3 answers

Look at my answer here: Can't figure out how gitignore ignores folders

Quote from this:

The following discussion was useful: http://git.661346.n2.nabble.com/negated-list-in-gitignore-no-fun-td1675067.html , especially the following from Linus:

This is by design. You have chosen to ignore these directories; They match "*". So git add. 'does not go down in them looking for files.

So, basically, for each level that you must enter, do not undo this folder, and ignore the contents in this folder.

In addition, you should look at the presence of .gitignore in a subdirectory, and not at the root level, only when it becomes quite complicated if you need to go to the subdirectory level from the root .gitignore due to the explanation above, according to which for each level , you must not divulge the folder, and then ignore the contents, etc.

+5
source share

Did some research here. What worked for me:

 /* !/directory !/another /another/* !/another/directory 

With these subdirectories /directory were tracked correctly. Curiously, this does not work with either one, nor with / , or only with * in the first line - I'm not sure why.

+5
source share
 /** !/**/ !/app/design/frontend/default/theme_name/** !/skin/frontend/default/theme_name/** 

Explaination:

  • ignore all files and folders recursively (note the double asterisk).
  • exclude all folders recursively (git by design will not create empty folders for which a full folder with ignored files is considered. We need this, so the next two exclude work)
  • Exclude all files and folders recursively from this location.
  • Exclude all files and folders recursively from this location.

I usually do this in subfolders, so I donโ€™t know if the first line will work.

0
source share

All Articles