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.
As a previous answer mentioned, passing the
-F
option to less causes it to quit if the content is less than one screen, however after doing so the screen is reset and you end up not seeing the content, the-X
option does away with that behaviour. So, I use the following to enable conditional paging based on the amount of content:The recent changes in the documentation mention a different way of removing a default option for
less
("default options" beingFRSX
).For this question, this would be (git 1.8+)
For example, Dirk Bester suggests in the comments:
Wilson F mentions in the comments and in his question that:
Those modifications were already visible in git 1.8.x, as illustrated in "Always use the pager for
git diff
" (see the comments). But the documentation just got reworded (for git 1.8.5 or 1.9, Q4 2013).See commit 97d01f2a for the reason behind the new documentation wording:
config: rewrite
core.pager
documentationNote: commit b327583 (Matthieu Moy
moy
, April 2014, for git 2.0.x/2.1, Q3 2014) will remove the S by default:pager: remove 'S' from $LESS by default
would appear identical to:
The documentation will read:
Use
to get rid of pager for all commands for all repositories.
You can also disable paging for single git subcommands by using
pager.<cmd>
setting instead ofcore.pager
and you can change your settings per git repository (omit--global
).See
man git-config
and search forpager.<cmd>
for details.This worked for me with git version 2.1.4 in Linux:
This makes git use
cat
instead ofless
.cat
just dumps the output ofdiff
to the screen with out any paging.You can add an alias to diff with its own pager with pager.alias, like so:
This will keep the color on and use 'cat' as the pager when invoked at 'git dc'.
Also, things not to do: