Search code examples
regexgitpcregit-log

Why is git-log with perl regex negative lookbehind causing a fatal error?


Either I cannot get git-log's regexp grep functionality to search using perl based regexp (pcre) or I can but it is not working with negative lookbehind.

git log -p -P -G'(?<!-)title'

results in output

fatal: invalid regex: Invalid preceding regular expression

However, pcre support and negative lookbehind seems to be working, if git-grep is any indicator. E.g. git grep -P '(?<!-)title' returns expected results.

git version 2.21.0 (Apple Git-122.2)


Solution

  • The -P doesn't influence -G. You can verify it by replacing -P with -F (or --fixed-string): you'll still get the same error, even if there's no look-around at all in fixed strings.

    The documentation of -P says

    Consider the limiting patterns to be Perl-compatible regular expressions.

    Note the word "patterns". Indeed, the --grep options mentions it:

    --grep=<pattern>

    On the other hand, -G doesn't:

    -G<regex>