git diff displays colors incorrectly

遇到几次了,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 pagerless 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 LESSis 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值