git gui - 可以显示 UTF-16 吗?
有没有办法让 git gui 以某种方式显示和显示 UTF-16 文件的差异?
我找到了一些信息,但是这主要指的是命令行而不是 GUI。
Is there a way to make git gui
display and show diffs for UTF-16 files somehow?
I found some information, but this is mostly referring to the command line rather than the GUI.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 msysGit 人员的帮助下,我一直在研究一个更好的解决方案,并提出了这个干净/污迹过滤器。该过滤器使用 Gnu file 和 iconv 命令来确定文件的类型,并将其与 msysGit 的内部 UTF-8 格式相互转换。
这种类型的清洁/污迹过滤器为您提供了更大的灵活性。在大多数情况下,它应该允许 Git 将混合格式文件视为 UTF-8 文本:diff、merge、git-grep,以及 gitattributes 属性,如 eol-conversion、ident-replacement 和内置 diff 模式。
上面概述的 diff 过滤器解决方案仅适用于 diff,因此受到更多限制。
要设置此过滤器:
将以下内容添加到 ~\Git\etc\gitconfig:
在全局 ~/Git/etc/gitattributes 或本地 ~/.gitattributes 中添加一行以处理混合格式文本,例如:
<前><代码>*.txt 过滤器=混合文本
我在包含 ANSI、UTF 格式的 sql 文件的目录上使用了此行-16 和 UTF-8 格式。到目前为止它正在发挥作用。不出意外的话,这看起来 20% 的努力就可以解决 80% 的 Windows 文本格式问题。
I have been working on a much better solution with help from the msysGit people, and have come up with this clean/smudge filter. The filter uses the Gnu file and iconv commands to determine the type of the file, and convert it to and from msysGit's internal UTF-8 format.
This type of Clean/Smudge Filter gives you much more flexibility. It should allow Git to treat your mixed-format files as UTF-8 text in most cases: diffs, merge, git-grep, as well as gitattributes properties like eol-conversion, ident-replacement, and built-in diff patterns.
The diff filter solution outlined above only works for diffs, and so is much more limited.
To set up this filter:
Add the following to ~\Git\etc\gitconfig:
Add a line to your global ~/Git/etc/gitattributes or local ~/.gitattributes to handle mixed format text, for example:
I have used this on a directory with sql files in ANSI, UTF-16, and UTF-8 formats. It is working so far. Barring any surprises, this looks like the 20% effort that could cover 80% of all Windows text format problems.
此方法适用于MSysGit 1.8.1,并在Windows XP上进行了测试。我使用 Git Extensions 2.44,但由于更改是在 Git 级别进行的,因此它们也应该适用于 Git Gui。步骤:
安装Gnu Iconv。
创建以下脚本,将其命名为
astextutf16
,并将其放置在 Git 安装的 /bin 目录中(这基于现有的astextplain
脚本):< /p><前><代码>#!/bin/sh -e
# 将 Windows Unicode (UTF-16 / UCS-2) 转换为 Git 友好的 UTF-8
# 注意:
# * 需要 Gnu iconv:
# http://gnuwin32.sourceforge.net/packages/libiconv.htm
# * 该脚本必须放置在:~/Git/bin
# * 修改全局 ~/Git/etc/gitconfig 或本地 ~/.git/config:
# [差异“astextutf16”]
# 文本转换 = astextutf16
# * 或者,从命令行:
# $ git config diff.astextutf16.textconv astextutf16
# * 修改全局 ~/Git/etc/gitattributes 或本地 ~/.gitattributes:
# *.txt diff=astextutf16
如果测试 "$#" != 1 ;然后
echo "用法: astextutf16 <文件>" 1>&2
1号出口
菲
# -f(rom) utf-16 -t(o) utf-8
“\Program Files\GnuWin32\bin\iconv.exe”-f utf-16 -t utf-8“$1”
出口0
修改全局 ~/Git/etc/gitconfig 或本地 ~/.git/config 文件,并添加以下行:
或者,从命令行:
$ git config diff.astextutf16.textconv astextutf16
修改全局 ~/Git/etc/gitattributes 或本地 ~/.gitattributes 文件,并映射要转换的扩展名:
*.txt diff=astextutf16
测试。 UTF-16 文件现在应该可见。
This method is for MSysGit 1.8.1, and is tested on Windows XP. I use Git Extensions 2.44, but since the changes are at the Git level, they should work for Git Gui as well. Steps:
Install Gnu Iconv.
Create the following script, name it
astextutf16
, and place it in the /bin directory of your Git installation (this is based on the existingastextplain
script):Modify the global ~/Git/etc/gitconfig or your local ~/.git/config file, and add these lines:
Or, from command line:
$ git config diff.astextutf16.textconv astextutf16
Modify the global ~/Git/etc/gitattributes or your local ~/.gitattributes file, and map your extensions to be converted:
*.txt diff=astextutf16
Test. UTF-16 files should now be visible.
我遇到了类似的问题。
我想改进已接受的答案,因为它有一个小缺陷。我遇到的问题是,如果该文件不存在,我会收到以下错误:
我更改了命令,以便不需要文件。它仅使用 标准输入 和 标准输出。这解决了这个问题。我的 .git/config 文件现在如下所示:
要在 .git/config 文件中创建条目,请使用以下命令:
我的 .gitattributes 文件如下所示:
仅指定可能成为问题的文件,否则清理/涂抹必须做更多工作(临时文件)。
我们还将 Git 中的 UTF-16LE 文件批量转换为 UTF- 8,因为这是最紧凑、最可移植的 UTF 编码。在 clean 和 smudge 中使用的相同 iconv 命令非常适合永久转换文件。
clean/smudge 命令的好处是,即使使用 UTF-16LE 等方式签入文件,差异仍然有效。
I ran into a similar issue.
I would like to improved on the accepted answer, since it has a small flaw. The problem I ran into was that if the file did not exist, I received this error:
I changed the commands so that a file is not required. It uses only standard input and standard output. This fixed the issue. My .git/config file now looks like this:
To create the entries in your .git/config file use these commands:
My .gitattributes file looks like this:
Specify only the files that might be an issue otherwise the clean/smudge has to do more work (temp files).
We also bulk converted the UTF-16LE files in Git to UTF-8 since this is the most compact and portable encoding for UTF. The same iconv command used in clean and smudge was perfect for permanently converting the files.
The nice thing about the clean/smudge commands is that even if a file is checked in with, say, UTF-16LE, the diff will still work.