Extended regular expressions (ERE) for .gitignore

孤人 提交于 2019-11-26 18:21:23

问题


Is there a way to use extended regular expressions(ERE) in a .gitignore file? For example I want to use the + repetition character in a .gitignore file. Is there a way to do that?


回答1:


As illustrated here and detailed in "this question", the function fnmatch() is involved to interpret glob patterns, which means regular expressions are not supported.

This is what gitignore man page mentions:

Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname.
For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".

You can see some correspondence between glob patterns and regular expressions in those questions.




回答2:


The .gitignore (and other) files use filename globs, not regular expressions.

I very much doubt you can convince the git hackers to change that: Just too ingrained by now, and globs are much more familiar as filename matchers.



来源:https://stackoverflow.com/questions/15672613/extended-regular-expressions-ere-for-gitignore

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