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

I wanted to find a commit containing either the string "hello world" or any commit containing this phrase inside the file.

git log -SHello World not working

git log -S'Hello World' not working

git log -S"hello world" does not work

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

+5
source share
3 answers

Search picks ( git log -S ) searches for the addition or removal of a word in a commit (and not in a commit message).
See Comment on this answer .

If you have a commit message that includes this word, but the content commit itself does not have β€œ hello world ” as being added or deleted (that is, for example, it already exists from previous commits) that are not reported.

In addition, git log -S 'This repos' or git log -S'This repos' should work fine.

+5
source

I wanted to find a commit that either contains the string "hello world"

To do a search, this is pretty simple:

 git log | grep "new image" 

or any commit that includes this phrase inside the file. To do this, you will need to focus on each commit, check it, and then find the index line.

For this task you will need to use git filter-branch ...

 # you will need something like: git filter-branch --tree-filter " find . -type f -exec grep -rnw '/path/to/somewhere/' -e "pattern"" 
0
source

How about the team git log "-Shello world" ?

0
source

Source: https://habr.com/ru/post/1237426/


All Articles