Search for a string in all of the files in git's staging area and all those files changed but not staged

I am trying to search for a string (e.g. search for string "TODO") in all of my files which are changed locally. That includes files which were already staged and those that are changed but are not added to staging area yet.


Solution 1:

Answering my own question. I was able to do it with the following command

git diff --name-only | xargs grep 'My search string goes here'

Solution 2:

The correct answer would be

git diff-index -S{STRINGTOSEARCH} -u HEAD

newly added files have to be added to staging through

git add path/to/filename

searches the intented string in only added/removed strings.