45

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
1

1 Answer 1

67

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' 
Sign up to request clarification or add additional context in comments.

9 Comments

git does not use FRSX by default. I suspect you are getting those defaults from the environment variable LESS, or from GIT_PAGER, which suggests another (imo simpler) solution. Namely, ensure that F does not appear in LESS or in GIT_PAGER. If git does use defaults when PAGER and GIT_PAGER are unset, that would surprise me, but perhaps I'm wrong about that. Documentation?
@WilliamPursell: The Git Documentation has been recently updated to disable options in a more backwards compatible way. My code was directly copied from the (old) man page – I have updated it now. The documentation also writes »Git sets the LESS variable to FSRX if it is unset«
May want to add '-r' to enable interpreting ANSI colors.
You may also want -c, which causes the output to always start at the top and fill the screen.
Do not ever use -r unless you really know what you're doing, always prefer -R. I just spent like half an hour debugging this. "-R" means "pass through escape codes that less understands, and update less's model of the terminal." Whereas "-r" means "pass through all escape codes and ignore them; good luck." (This generally mangles the output in subtle ways.)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.