在 Mac OS X Mavericks 上使用 git diff 时如何摆脱 ESC[ 字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20414596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get rid of ESC[ characters when using git diff on Mac OS X Mavericks?
提问by yan
Since I installed OS X Mavericks, the result of the command git diff
is rendering ESC[xxx
characters like this:
由于我安装了 OS X Mavericks,命令的结果git diff
是渲染这样的ESC[xxx
字符:
ESC[1mdiff --git a/console/org.linkedin.glu.console-webapp/decorate-grails-methods-plugin/plugin.xml b/console/org.linkedin.glu.console-webapp/decorate-grails-methods-plugin/plugin.xmlESC[m
ESC[1mindex 3b65cf1..0ca5d7e 100644ESC[m
ESC[1m--- a/console/org.linkedin.glu.console-webapp/decorate-grails-methods-plugin/plugin.xmlESC[m
ESC[1m+++ b/console/org.linkedin.glu.console-webapp/decorate-grails-methods-plugin/plugin.xmlESC[m
ESC[36m@@ -15,14 +15,14 @@ESC[m ESC[mThe purpose of this plugin is to decorate various grails methods.ESC[m
This used to render properly prior to installing Mavericks. I have no clue what is different so any help in troubleshooting would be much appreciated.
这用于在安装 Mavericks 之前正确渲染。我不知道有什么不同,因此非常感谢您对故障排除的任何帮助。
Note that the pager used is less
since when I hit h
I get the following:
请注意,使用的寻呼机是less
因为当我点击时,h
我得到以下信息:
SUMMARY OF LESS COMMANDS
Commands marked with * may be preceded by a number, N.
Notes in parentheses indicate the behavior if N is given.
回答by John Szakmeister
Do you have a LESS
environment variable set? You can check using:
你有设置LESS
环境变量吗?您可以使用以下方法检查:
env | grep LESS
or:
或者:
echo $LESS
If so, you want to make sure the R
option is in there. That allows the ANSI escape sequences to pass through unscathed, and they'll be rendered as colors in the terminal.
如果是这样,您要确保该R
选项在那里。这允许 ANSI 转义序列毫发无损地通过,并且它们将在终端中呈现为颜色。
Just for reference, I use this:
仅供参考,我用这个:
export LESS=eFRX
回答by FreshPow
This works:
这有效:
git config --global core.pager "less -r"
回答by Sri Murthy Upadhyayula
The global pager configuration option within git, just sends the output stream to the more
or less
commands. You can get rid of the escape characters within this output by setting the global configuration option to either:
git 中的全局寻呼机配置选项,只是将输出流发送到more
orless
命令。您可以通过将全局配置选项设置为:
git config --global core.pager "more -R"
To continue using more
as your pager or
继续more
用作您的寻呼机或
git config --global core.pager "less -R"
To continue using less
as your pager
继续less
用作您的寻呼机
回答by StackzOfZtuff
Try "less -R" (big "R")
尝试“less -R”(大“R”)
This worked for me:
这对我有用:
git config core.pager 'less -R'
"less -R" vs. "less -r"
“少-R”与“少-r”
"-R" (big R) seems to be the safer version of "-r" (small r). So that's why I prefer the big R version.
“-R”(大 R)似乎是“-r”(小 r)的更安全版本。所以这就是我更喜欢大 R 版本的原因。
Quote from man less:
引自man less:
-r or --raw-control-chars
Causes "raw" control characters to be displayed. The default is to display control characters using the caret notation; for example, a control-A (octal 001) is displayed as "^A". Warning: when the -r option is used, less cannot keep track of the actual appearance of the screen (since this depends on how the screen responds to each type of control character). Thus, various display problems may result, such as long lines being split in the wrong place.-R or --RAW-CONTROL-CHARS
Like -r, but only ANSI "color" escape sequences are output in "raw" form. Unlike -r, the screen appearance is maintained correctly in most cases. ANSI "color" escape sequences are sequences of the form:ESC [ ... m
where the "..." is zero or more color specification characters For the purpose of keeping track of screen appearance, ANSI color escape sequences are assumed to not move the cursor. You can make less think that characters other than "m" can end ANSI color escape sequences by setting the environment variable LESSANSIENDCHARS to the list of characters which can end a color escape sequence. And you can make less think that characters other than the standard ones may appear between the ESC and the m by setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear.
-r 或 --raw-control-chars
导致显示“原始”控制字符。默认是使用插入符号显示控制字符;例如,控件-A(八进制 001)显示为“^A”。警告:当使用 -r 选项时,less 无法跟踪屏幕的实际外观(因为这取决于屏幕如何响应每种类型的控制字符)。因此,可能会导致各种显示问题,例如在错误的位置拆分长行。-R 或 --RAW-CONTROL-CHARS
与 -r 类似,但只有 ANSI“颜色”转义序列以“原始”形式输出。与 -r 不同的是,在大多数情况下,屏幕外观保持正确。ANSI“颜色”转义序列是以下形式的序列:ESC [ ... 米
其中“...”是零个或多个颜色规范字符 为了跟踪屏幕外观,假定 ANSI 颜色转义序列不移动光标。通过将环境变量 LESSANSIENDCHARS 设置为可以结束颜色转义序列的字符列表,您可以减少认为“m”以外的字符可以结束 ANSI 颜色转义序列。并且您可以通过将环境变量 LESSANSIMIDCHARS 设置为可以出现的字符列表来减少认为在 ESC 和 m 之间可能出现标准字符以外的字符。
回答by skr
You change use the option -R
Repaint the screen to remove all the buffered input.
您更改使用选项重新-R
绘制屏幕以删除所有缓冲输入。
export LESS="$LESS -R"
回答by jhfrontz
Another alternative is to eliminate git's "colorizing" of output by doing something like
另一种选择是通过执行类似的操作来消除 git 对输出的“着色”
$ git config --global color.ui false
See git help config
for details.
详情请参阅git help config
。
Reference: unix.stackexchange: How to colorize output of git?