Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git grep in only untracked files

Tags:

git

grep

command

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 ?

like image 894
Charles Avatar asked Oct 17 '25 18:10

Charles


1 Answers

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

  • Git: list only "untracked" files (also, custom commands)
  • https://unix.stackexchange.com/questions/20262/how-do-i-pass-a-list-of-files-to-grep
like image 127
Valarpirai Avatar answered Oct 19 '25 12:10

Valarpirai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!