Boolean_Type
Boolean_Type

Reputation: 1274

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.

Upvotes: 3

Views: 643

Answers (1)

VonC
VonC

Reputation: 1328912

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.

Upvotes: 2

Related Questions