git log -S'带换行符的字符串'

git log -S'string with line breaks'

我在项目中有以下代码:

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

我想查找包含两个字符串的日志,参数为 -S。 我试过:

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

...但没有成功。

git log -S (or -G) does not support an --and directive like git grep does: see "Fun with "git log --grep""(这是一个类似的问题)

"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

OP Boolean_Type suggests 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

注意:如果在 Windows CMD 中完成,请使用双引号:

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

从那里,git show 可以突出显示添加或删除的行。