git

How to search for a string across all staged files and unstaged changes in Git?


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

  • 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'