Search code examples
gitgit-log

git log -S'string with line breaks'


I have the following code in project:

someMethodCall();
anotherMethodCall(); //new string

I want to find logs, which contains that both srings, with -S parameter. I've tried:

git log -S'someMethodCall();anotherMethodCall()'
git log -S'someMethodCall();%nanotherMethodCall()'
git log -S'someMethodCall();\r\nanotherMethodCall()'
git log -S'someMethodCall();\nanotherMethodCall()'

...but no success.


Solution

  • git log -S (or -G) does not support an --and directive like git grep does: see "Fun with "git log --grep"" (which is a similar issue)

    "git log --grep" is line oriented.
    That is partly the reason why "git log" family does not support --and option to begin with. The and semantics is not very useful in the context of "git log" command, and this is true even if we limit the discussion to the message part

    The OP Boolean_Type suggests in the comments adding the --pickaxe-regex option:

    Treat the <string> given to -S as an extended POSIX regular expression to match.

    git log -S'(anotherMethodCall\(\);)|(someMethodCall\(\);)' --pickaxe-regex
    

    Note: if done in a Windows CMD, use double-quotes:

    git log -S"(anotherMethodCall\(\);)|(someMethodCall\(\);)" --pickaxe-regex
    

    From there, a git show can highlight the lines added or deleted.