Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

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.

1 Answer

0 votes
by (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

Other options from the comments include:

# set an evaporating environment variable to use cat for your pager

GIT_PAGER=cat git diff

# Now you need to tell less not to paginate if less than a page

export LESS="-F -X $LESS"

#then git as usual

git diff

Related questions

Browse Categories

...