我有一个带unicode符号的文件(俄文).当我修正一些拼写错误时,我git diff --color-words=.会看到我所做的改变.
在unicode(西里尔文)符号的情况下,我得到一些像尖括号一样混乱:
$ cat p1
??????
$ cat p2
??????
$ git diff --color-words=. --no-index p1 p2
diff --git 1/p1 2/p2
index d0f56e1..d84c480 100644
--- 1/p1
+++ 2/p2
@@ -1 +1 @@
<D0><BF><9F>?????
Run Code Online (Sandbox Code Playgroud)
看起来像git diff --color-words=.检查字节之间的差异而不是像我期望的那样检查符号之间的差异.
有没有办法告诉git使用unicode符号正常工作?
关于我的环境的UPD:我在Mac OS和Linux主机上也是如此.
我的shell变量是:
BASH=/bin/bash
HOSTTYPE=x86_64
LANG=ru_RU.UTF-8
OSTYPE=darwin10.0
PS1='\h:\W \u\$ '
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
TERM=xterm-256color
TERM_PROGRAM=iTerm.app
_=-l
Run Code Online (Sandbox Code Playgroud)
我已将git config重置为默认设置,如下所示:
$ git config -l
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
Run Code Online (Sandbox Code Playgroud)
git版本
$ git --version
git version 1.7.3.5
Run Code Online (Sandbox Code Playgroud)
too*_*ear 27
对我来说less- git寻呼机 - 应该受到责备(感谢@kostix).通过完全禁用寻呼机进行实验:
git --no-pager diff p1 p2
Run Code Online (Sandbox Code Playgroud)
我的案例是包含表情符号的提交消息; 但它基本上是同样的问题.
$ git log --oneline
93a1866 <U+1F43C>
$ git --no-pager log --oneline
93a1866
$ export LESS='--raw-control-chars'
$ git log --oneline
93a1866
$ git config --global core.pager 'less --raw-control-chars'
$ git log --oneline
93a1866
Run Code Online (Sandbox Code Playgroud)
注意:该--RAW-CONTROL-CHARS选项导致less通过ANSI颜色转义,但仍然会使其他控制字符(包括表情符号).我less的全局配置--RAW-CONTROL-CHARS和我的git寻呼机--raw-control-chars如上所述.
我的解决方案是使用 git difftool。
我基于https://code.google.com/p/google-diff-match-patch/编写了这个工具https://github.com/chestozo/dmp。
有时它还提供了更好的差异比较git diff --color-words=.:)