Freebsd – “git show” shows strange characters on XTerm

freebsdgitxterm

On FreeBSD 10.3, I run a command like git show on xterm, the output contains some strange irrelevant characters as below. I'm not sure why.

enter image description here

Best Answer

Your pager seems to be configured to render the Esc character (used in escape sequences to change the text colour) as ESC instead of passing it directly to the terminal (that's independent from the terminal emulator, in your case xterm).

Try setting (sh syntax).

PAGER=less LESS=R
export PAGER LESS

Or ((t)csh syntax):

setenv PAGER less
setenv LESS R

To select GNU less as your pager and tell less to pass text formatting escape sequences through. If you don't set the LESS variable, git sets it to FRX (so includes R already, but also F and X which you may want as well). So you may want to omit that part if you prefer the FRX behaviour (see less man page for details), or unset LESS it if you had it set to a different value, or set it yourself to FRX.

That PAGER environment variable is used by a few things (like man) beside git. If you want to change your pager only for git, you can set the GIT_PAGER environment variable instead.

Alternatively, you can do:

git config --global core.pager 'less -FRX'

You can tell git to not use colour when using a pager with:

git config --global color.pager false

See env PAGER=less git config --help for details.