How do you get git grep
to return results without a pager? Grep does this by default. When I pipe git grep
to cat: git grep foo | cat
it does this but it loses the highlighting on the match. I want to keep the highlighting on the match without doing git grep foo | cat | grep foo
.
Git uses pager when you run git diff , git show , git grep etc. If you want to see the result without pager, just add --no-pager or -P .
Git Grep. Git ships with a command called grep that allows you to easily search through any committed tree, the working directory, or even the index for a string or regular expression. For the examples that follow, we'll search through the source code for Git itself.
answered Jul 18, 2019 by debashis borgohain (27.5k points) --no-pager to git will tell it to not use a pager. Passing the option -F to less will tell it to not page if the output fits in a single screen. Usage: git --no-pager diff.
The git grep version will only search in files tracked by git, whereas the grep version will search everything in the directory. So far so similar; either one could be better depending on what you want to achieve.
You can either use the --no-pager
parameter like git --no-pager grep foo
or tell grep to always do the highlighting even if you pipe the result to some other process with git grep --color=always foo | cat
. Or you can set the config option core.pager
to cat
like git -c core.pager=cat grep foo
or of course permanently with git config core.pager cat
which will then work for all Git commands that would be sent to the pager and also preserves the highlighting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With