遇到几次了,git status颜色能正常显示,git log、git diff却是乱码,每次都去查找解决方法[1],记下之。
You're seeing the escape sequences that tell the terminal to change colors displayed with the escape character shown as ESC
, whereas the desired behavior would be that the escape sequences have their intended effect.
Commands such as git diff
and git log
pipe their output into a pager, less
by default. Git tries to tell less
to allow control characters to have their control effect, but this isn't working for you.
If less
is your pager but you have the environment variable LESS
set to a value that doesn't include -r
or -R
, git is unable to tell less
to display colors. It normally passes LESS=-FRSX
, but not if LESS
is already set in the environment. A fix is to explicitly pass the -R
option to tell less
to display colors when invoked by git:
git config --global core.pager 'less -R'
If less
isn't your pager, either switch to less
or figure out how to make your pager display colors.
If you don't want git to display colors when it's invoking a pager, set color.ui
to auto
instead of true
.
参考资料
[1] http://unix.stackexchange.com/questions/64927/git-diff-displays-colors-incorrectly