Git ignore all except subfolder

廉价感情. 提交于 2019-11-29 04:29:57
manojlds

Look at my answer here: Can't understand how gitignore ignores the folders

Quoting from that:

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

That's by design. You've chosen to ignore those directories; they match "*" themselves. Thus, 'git add .' doesn't descend into them looking for files.

So basically, for each level you have to go in, unignore that folder, and ignore contents within that folder.

Also, you should look at having .gitignore at subdirectory rather than at root level only as it becomes pretty complex if you have to go to the subdirectory level from the root .gitignore because of the explanation above, whereby for each level, you have to unignore the folder and then ignore the contents and so on.

Did some research here. What worked for me was:

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

With this subdirectories of /directory were tracked correctly. Curiously it doesn't work with either only / or only * on the first line - I am not sure why.

/**
!/**/
!/app/design/frontend/default/theme_name/**
!/skin/frontend/default/theme_name/**

Explaination:

  1. ignore all files and folders, recursively (note the double asterisk).
  2. exclude all folders, recursively (git by design will not commit empty folders, which a folder full of ignored files is counted as. We need this so that the next two excludes work)
  3. exclude all files and folders, recursively, from this location.
  4. exclude all files and folders, recursively, from this location.

I usually do this to sub-folders, so I don't know if the first line will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!