Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always use the pager for git diff

I'm using less as my Git pager.

If the git diff output is readable on one page, my Git prints the output to the screen.

Sometimes I'm too fast with typing Ctrl + D (half page down), which kills my terminal. Is there an option to enable the pager for git diff, even if the output is very small?

This doesn't work:

  • git -p diff
  • git --paginate diff
  • git settings: pager.diff = true
like image 327
Dave Halter Avatar asked Sep 10 '12 12:09

Dave Halter


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 .

What is pager in git?

When you run Git commands that produce a bunch of output, Git will use a pager to present the content starting at the beginning, rather than spitting it all out to the screen at once. This will almost always come in handy for commands like git-diff and git-log . By default, Git uses less as its pager.

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.

What does M in git diff mean?

^M represents carriage return. This diff means something removed a Unicode BOM from the beginning of the line and added a CR at the end.


1 Answers

This is controlled by the -F (--quit-if-one-screen) option to less.

Git uses the options FRSX for/of less by default, if none are specified by the $LESS or $GIT_PAGER environment variables. To change it, specify the core.pager option and set it to RSX:

git config --global core.pager 'less -+F' 

Older versions of Git used to recommend the following in their documentation:

git config --global core.pager 'less -+$LESS -RSX' 
like image 144
knittl Avatar answered Sep 23 '22 13:09

knittl