How do i get the git pager to clean up screen output after exit?

31

10

The pager less doesn't clear the screen as it should do when i use git.

I use less all the time and it usually doesn't leave output in the terminal after quit but when less gets executed via git it leaves the output in the terminal. I'm 100% sure git uses less on my system.

What is wrong with git and how do i fix it? pager = less in ~/.gitconfig doesn't help. $PAGER is also set to less.

ggustafsson

Posted 2011-12-11T19:20:26.430

Reputation: 1 698

To clarify, git doesn't clear the screen by default, there is nothing wrong with your git. Use @ggustafsson's answer to change the default behaviour. – LeartS – 2014-11-06T10:25:46.927

Answers

33

The solution is to set the variable LESS. Git defaults to less FRSX.

export LESS=R

Alternatively, you can modify the variable LESS when pager is called:

git config --global core.pager 'less -+$LESS -R'

See the core.pager section in man git-config

ggustafsson

Posted 2011-12-11T19:20:26.430

Reputation: 1 698

3Removing only X option is sufficient, the option is for preventing restoring the terminal according to the manual of less(1). – xuchunyang – 2016-10-26T08:26:14.103

11

To clear the screen, but leave other behaviors untouched, you can do

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

This disables the -X option for less.

Dan

Posted 2011-12-11T19:20:26.430

Reputation: 211

1You would also want to disable the 'F' flag, since less will automatically close if the buffer is small, leading you to believe that there is no output. So the command should be git config --global core.pager 'less -+X -+F'. – Steve – 2018-09-16T23:09:56.047