Git - Unignore any folder located anywhere inside repository that recursively allows everything

柔情痞子 提交于 2019-12-08 06:56:44

问题


How to unignore folder with a particular name (e.g. Sync) that can be located anywhere inside the repository and Recursively allow everything inside it, violating every other rule of gitignore?


回答1:


The solution proposed (!/**/Sync/**/*) would not work alone, because It is not possible to re-include a file if a parent directory of that file is excluded.

So if you have a .gitignore with:

*
!.gitignore

You must whitelist folders first (!*/) and then exclude files (!**/Sync/**, no need for **/*)

The end result would be a .gitignore like:

*
!.gitignore
!*/
!**/Sync/**

Don't forget to check with any file which .gitignore rule applies with:

git check-ignore -v -- aFile

Note: / would be needed (for !**/Sync/**) if you wanted to anchor the whitelist from the top of your repository.
If not, no / needed: this would be relative to wherever your .gitignore is).

From gitignore man page:

If the pattern does not contain a slash /, Git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).




回答2:


Update: In VONC's answer he is correct to mention about !*/ and the slash in the beginning of the pattern.

Unignore folder with a particular name (e.g. Sync) that can be located anywhere inside the repository and recursively allow everything inside it, violating every other rule of gitignore:

Inside .gitignore add the following:

*
!.gitignore
!*/
!/**/Sync/**


来源:https://stackoverflow.com/questions/50357571/git-unignore-any-folder-located-anywhere-inside-repository-that-recursively-al

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