4

I would like to grep inside Untracked files and in files from Changes not staged for commit but not in the rest.

Is it possible to achieve this with git grep ?

Charles
  • 11,367
  • 10
  • 77
  • 114

1 Answers1

4

To list untracked files try:

git ls-files --others --exclude-standard

To grep in untracked files.

grep 'search' $(git ls-files -m --others --exclude-standard)

replace the search word with your search string.

From man-page:

git-ls-files - Show information about files in the index and the working tree

-m, --modified
           Show modified files in the output
-o, --others
           Show other (i.e. untracked) files in the output
--exclude-standard
       Add the standard git exclusions: .git/info/exclude, .gitignore in each directory, and the user’s global exclusion file.

Credits goes to

Community
  • 1
  • 1
Valarpirai
  • 465
  • 3
  • 14