Extended regular expressions (ERE) for .gitignore

后端 未结 2 599
不思量自难忘°
不思量自难忘° 2020-12-03 06:27

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 .giti

相关标签:
2条回答
  • 2020-12-03 07:15

    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.

    0 讨论(0)
  • 2020-12-03 07:15

    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.

    0 讨论(0)
提交回复
热议问题