Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get `git grep` to return results without a pager? [duplicate]

Tags:

git

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.

like image 225
eatonphil Avatar asked Mar 02 '17 15:03

eatonphil


People also ask

How do I prevent git diff from using a pager?

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 .

How does git grep work?

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.

What is git -- No pager?

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.

Which statement is the best comparison between git grep and grep?

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.


1 Answers

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.

like image 71
Vampire Avatar answered Sep 21 '22 02:09

Vampire