Leave git diff result in terminal

I am using git in the terminal. When I need to make some changes, I use git diff to see what I changed. I would like the output result to remain in the terminal, so I can view it after pressing q , since when I press q , the results all disappear.

+4
source share
2 answers

This is because git displays it through a pager.

git --no-pager diff

It is configured to use the default pager configuration, you can change this default to use cat instead, so you don't have to type --no-pager using git config --global core.pager cat . Read more about the documents here .


The output to STDOUT and through the pager is much more complicated and requires tools that go beyond the regular redirection of unix and pipes. You can redirect the output to STDERR with tee , and pipe to less , which gives you the illusion. Note that this is a hack and abuses the idea of STDERR

git diff | tee /dev/stderr | less

You can make it an alias if you plan to use it often.

+13
source

All in all, I don't like less disappearing with content. Usually I set the environment variable less in eFRX :

 export LESS=eFRX 

This is X , which causes it to stop deleting content. F says you just need to exit if there is only one screen with content. R helps interpret the ANSI color codes (you need this for git diff ), and X forces it to stop clearing the screen before exiting.

This will make you happier with some other programs that also use less .

+6
source

All Articles