When I view a large diff with git diff
, it gets paged with less
. This is confirmed by opening another window and checking data from ps -aux
and /proc
.
However, when less
is invoked by Git, it does not revert the terminal content to its previous state after hitting q
(the diff content remains in terminal). But when I do
git diff commit1 commit2 --color | less -R
and quit less
with a key q
, the content disappears and the terminal reverts to the previous state.
More interestingly, if I do these
export PAGER=less LESS='-R'
and invoke git diff
(or any other command that calls a pager), less
behaves the same as if invoked directly from Bash shell.
Here's a brief screenshot describing my question. On the left pane the command are executed as following:
unset PAGER GIT_PAGER LESS
git diff HEAD^ HEAD
On the right pane you see the commands. The latest commit was 100+ lines of y
written to a file. On both panes less
is exited with key q
.
Can anyone tell me what is different and explain why?