无法让git与iconv和utf-16配合使用 [英] Can't get git to play nice with iconv and utf-16
问题描述
我试图让git将UTF-16识别为文本,以允许我将其作为文本进行区分和修补,但我无法获取 textconv
我可以手动调用
iconv -f utf-16 -t utf-8 some-utf-16-file.rc
一切正常。但是,如果我配置我的.gitconfig如下
[diffutf16]
textconv =iconv -f utf -16le -t utf-8
和我的.gitattributes:
#自定义MFC
$ p $但是,如果我运行
* .rc text eol = crlf diff = utf16
git diff
,则会显示以下内容:
$ b
iconv:C:/Users/Mahmoud/AppData/Local/Temp/IjLBZ8_OemKey.rc:104:1:不完整的字符或移位顺序
使用procmon,我可以将它追踪为创建此过程:
sh -ciconv.exe -f utf-16le -t utf-8 \$ @ \iconv.exe -f utf-16le -t utf- 8C:/Users/Mahmoud/AppData/Local/Temp/JLOkVa_OemKey.rc
...我真的可以正常运行(虽然在实际的文件中)。
任何想法?
(请请注意,我知道获取gi的各种解决方案t使用UTF-16。我特意试图解决这个为什么iconv本身起作用的问题,但在被git调用时不起作用。此外,这个错误最初是在尝试从重复问题链接解决方案时遇到的。 )
解决方案仅使用
diff
,它应该work:*。rc diff = utf16
text
和eol
会导致git替换之前的行尾将数据传递给iconv,之后它不再是有效的utf16,因为在评论中注明。I'm trying to get git to recognize UTF-16 as text to allow me to diff and patch as text natively, but I'm having trouble getting the
textconv
parameter to work.I can manually call
iconv -f utf-16 -t utf-8 some-utf-16-file.rc
and everything is fine. But if I configure my .gitconfig as follows
[diff "utf16"] textconv = "iconv -f utf-16le -t utf-8"
and my .gitattributes:
# Custom for MFC *.rc text eol=crlf diff=utf16
However, if I then if I run
git diff
, the following is displayed:iconv: C:/Users/Mahmoud/AppData/Local/Temp/IjLBZ8_OemKey.rc:104:1: incomplete character or shift sequence
With procmon I was able to track it down as creating this process:
sh -c "iconv.exe -f utf-16le -t utf-8 \"$@\"" "iconv.exe -f utf-16le -t utf-8" C:/Users/Mahmoud/AppData/Local/Temp/JLOkVa_OemKey.rc
...which I can actually run fine (on the actual file, though).
Any ideas?
(Please note that I'm aware of the various solutions for getting git to work with UTF-16. I'm specifically trying to address this question of why iconv by itself works but it will not work when called by git. Also, this error was originally encountered while trying one of the linked solutions from the "duplicate" question. Thank you all kindly.)
解决方案Use only
diff
, it should work:*.rc diff=utf16
text
andeol
cause git to substitute end-of-lines before passing data to iconv, after which it is not a valid utf16 anymore, as noted in comments.这篇关于无法让git与iconv和utf-16配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文