Search code examples
gitgit-log

How can I pass a string to git log -S instead of just a word?


I wanted to search for the commit that either contains the string "hello world" or any commit that included that phrase inside of a file.

git log -SHello World doesn't work

git log -S'Hello World' doesn't work

git log -S"hello world" doesn't work

I have been using: git log -i --grep='hello world' but this one only works for commit messages.


Solution

  • The pickaxe search (git log -S) looks for the addition or removal of a word in a commit (and not in a commit message).
    See the comment on this answer.

    If you have a commit message which includes that word, but the commit content itself does not have "hello world" as being added or removed (meaning, for instance, it is already there, from previous commits), that commit would not be reported.

    Other than that, git log -S 'This repos' or git log -S'This repos' should work just fine.