I use Git in the terminal. When I have to make some changes, I use git diff
to see what I have changed. I'd like that output result to stay in the terminal, so I can review it after I press Q, since when I do press Q, the results all disappear.
This happens because Git is outputting it through a pager. Instead, use:
git --no-pager diff
It is set to use a pager by the default configuration, and you can change this default to use cat
instead to prevent you from having to type --no-pager
with git config --global core.pager cat
. You can read more in the documentation here.
Outputting to STDOUT
and through a pager is much more complicated and requires tools beyond the scope of regular Unix redirection and pipes.
You can redirect the output to STDERR
with tee
and pipe to less
, which gives the illusion of you want. Note this is a hack and abuses the idea of STDERR
git diff | tee /dev/stderr | less
You may want to make this an alias if you intend on using it frequently.
In general, I don't like less
disappearing with the contents either. I typically set my LESS
environment variable to eFRX
:
export LESS=eFRX
It's the X
that makes it stop taking the away the content. The F
says to just exit if there is only one screens worth of content. The R
helps to interpret ANSI color codes (you'll want that for git diff
), and the X
makes it stop clearing the screen before exiting.
It will make you happier with some other programs that use less
too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With