Is there a command line switch to pass to git diff
and other commands that use the less
pager by default?
I know I can pipe it to cat, but that removes all the syntax highlighting.
I know I can set the pager in the global .gitconfig to cat by GITPAGER=cat
(or something like that); but I want to have pager sometimes (depending on the size of the diff).
But, I would prefer a command line switch if there is one; and I am not able to find one, going through the man pages.
You can disable/enable pagers for specific outputs in global config as well:
Or to set the core.pager option, just provide an empty string:
This is better in my opinion than setting it to
cat
as you say.For a quick-and-dirty script I wrote, I did it this way:
I like to disable paging from time to time, when I know the output is not very long. For this, I found a neat trick using git aliases:
Or add the following to the
[alias]
section of ~/.gitconfig:This means that you can use the prefix
n
to turn off paging for any git command, i.e.:As it says on man git, you can use
--no-pager
on any command.I use it on:
Then use an alias to avoid using (and remembering) long commands.
Regarding the disabled color when piping:
Use
--color
to avoid that coloring is disabled.git diff --color | less -R
Or configure it forced on (in e.g. .gitconfig):
git diff | less -R
For non-color tools, then use:
git diff --no-color | some-primitive-tool
Exporting environment variable
LESS=-R
(in e.g. .bashrc) turns on color support by default in "less":git diff | less
--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:
Other options from the comments include: