git gui - 可以显示 UTF-16 吗?

发布于 2024-09-26 23:15:22 字数 186 浏览 0 评论 0原文

有没有办法让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光沙漏 2024-10-03 23:15:22

在 msysGit 人员的帮助下,我一直在研究一个更好的解决方案,并提出了这个干净/污迹过滤器。该过滤器使用 Gnu file 和 iconv 命令来确定文件的类型,并将其与 msysGit 的内部 UTF-8 格式相互转换。

这种类型的清洁/污迹过滤器为您提供了更大的灵活性。在大多数情况下,它应该允许 Git 将混合格式文件视为 UTF-8 文本:diff、merge、git-grep,以及 gitattributes 属性,如 eol-conversion、ident-replacement 和内置 diff 模式。

上面概述的 diff 过滤器解决方案仅适用于 diff,因此受到更多限制。

要设置此过滤器:

  1. 获取 Gnu libiconv文件,并安装两者。
  2. 确保 GnuWin32\bin 目录(通常为“C:\Program Files\GnuWin32\bin”)位于 %PATH% 中
  3. 将以下内容添加到 ~\Git\etc\gitconfig:

    [过滤器“混合文本”]
        clean = iconv -sc -f $(文件-b --mime-编码 %f) -t utf-8
        涂抹= iconv -sc -f utf-8 -t $(文件-b --mime-编码 %f)
        必需的
    
  4. 在全局 ~/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:

  1. Get Gnu libiconv, and file, and install both.
  2. Ensure that the GnuWin32\bin directory (usually "C:\Program Files\GnuWin32\bin") is in your %PATH%
  3. Add the following to ~\Git\etc\gitconfig:

    [filter "mixedtext"]
        clean = iconv -sc -f $(file -b --mime-encoding %f) -t utf-8
        smudge = iconv -sc -f utf-8 -t $(file -b --mime-encoding %f)
        required
    
  4. Add a line to your global ~/Git/etc/gitattributes or local ~/.gitattributes to handle mixed format text, for example:

    *.txt filter=mixedtext
    

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.

友谊不毕业 2024-10-03 23:15:22

此方法适用于MSysGit 1.8.1,并在Windows XP上进行了测试。我使用 Git Extensions 2.44,但由于更改是在 Git 级别进行的,因此它们也应该适用于 Git Gui。步骤:

  1. 安装Gnu Iconv

  2. 创建以下脚本,将其命名为 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

  3. 修改全局 ~/Git/etc/gitconfig 或本地 ~/.git/config 文件,并添加以下行:

    [diff“astextutf16”]  
        文本转换 = astextutf16
    
  4. 或者,从命令行:

    $ git config diff.astextutf16.textconv astextutf16

  5. 修改全局 ~/Git/etc/gitattributes 或本地 ~/.gitattributes 文件,并映射要转换的扩展名:

    *.txt diff=astextutf16

  6. 测试。 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:

  1. Install Gnu Iconv.

  2. Create the following script, name it astextutf16, and place it in the /bin directory of your Git installation (this is based on the existing astextplain script):

    #!/bin/sh -e
    # converts Windows Unicode (UTF-16 / UCS-2) to Git-friendly UTF-8
    # notes:
    # * requires Gnu iconv:
    #       http://gnuwin32.sourceforge.net/packages/libiconv.htm
    # * this script must be placed in: ~/Git/bin
    # * modify global ~/Git/etc/gitconfig or local ~/.git/config:
    #       [diff "astextutf16"]
    #           textconv = astextutf16
    # * or, from command line:
    #       $ git config diff.astextutf16.textconv astextutf16
    # * modify global ~/Git/etc/gitattributes or local ~/.gitattributes:
    #       *.txt diff=astextutf16
    if test "$#" != 1 ; then
        echo "Usage: astextutf16 <file>" 1>&2
        exit 1
    fi
    # -f(rom) utf-16 -t(o) utf-8
    "\Program Files\GnuWin32\bin\iconv.exe" -f utf-16 -t utf-8 "$1"
    exit 0
    
  3. Modify the global ~/Git/etc/gitconfig or your local ~/.git/config file, and add these lines:

    [diff "astextutf16"]  
        textconv = astextutf16
    
  4. Or, from command line:

    $ git config diff.astextutf16.textconv astextutf16

  5. Modify the global ~/Git/etc/gitattributes or your local ~/.gitattributes file, and map your extensions to be converted:

    *.txt diff=astextutf16

  6. Test. UTF-16 files should now be visible.

暖风昔人 2024-10-03 23:15:22

我遇到了类似的问题。

我想改进已接受的答案,因为它有一个小缺陷。我遇到的问题是,如果该文件不存在,我会收到以下错误:

转换为无法不受支持

我更改了命令,以便不需要文件。它仅使用 标准输入标准输出。这解决了这个问题。我的 .git/config 文件现在如下所示:

[filter "mixedtext"]
    clean = "GITTMP=$(mktemp);TYPE=$( tee $GITTMP|file -b --mime-encoding - ); cat $GITTMP | iconv -sc -f $TYPE -t utf-8; rm -f $GITTMP"
    smudge = "GITTMP=$(mktemp);TYPE=$( tee $GITTMP|file -b --mime-encoding - ); cat $GITTMP | iconv -sc -f utf-8 -t $TYPE; rm -f $GITTMP"
    required = true

要在 .git/config 文件中创建条目,请使用以下命令:

git config --replace-all filter.mixedtext.clean 'GITTMP=$(mktemp);TYPE=$( tee $GITTMP|file -b --mime-encoding - ); cat $GITTMP | iconv -sc -f $TYPE -t utf-8; rm -f $GITTMP'
git config --replace-all filter.mixedtext.smudge 'GITTMP=$(mktemp);TYPE=$( tee $GITTMP|file -b --mime-encoding - ); cat $GITTMP | iconv -sc -f utf-8 -t $TYPE; rm -f $GITTMP'
git config --replace-all filter.mixedtext.required true

我的 .gitattributes 文件如下所示:

*.txt filter=mixedtext
*.ps1 filter=mixedtext
*.sql filter=mixedtext

仅指定可能成为问题的文件,否则清理/涂抹必须做更多工作(临时文件)。

我们还将 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:

conversion to cannot unsupported

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:

[filter "mixedtext"]
    clean = "GITTMP=$(mktemp);TYPE=$( tee $GITTMP|file -b --mime-encoding - ); cat $GITTMP | iconv -sc -f $TYPE -t utf-8; rm -f $GITTMP"
    smudge = "GITTMP=$(mktemp);TYPE=$( tee $GITTMP|file -b --mime-encoding - ); cat $GITTMP | iconv -sc -f utf-8 -t $TYPE; rm -f $GITTMP"
    required = true

To create the entries in your .git/config file use these commands:

git config --replace-all filter.mixedtext.clean 'GITTMP=$(mktemp);TYPE=$( tee $GITTMP|file -b --mime-encoding - ); cat $GITTMP | iconv -sc -f $TYPE -t utf-8; rm -f $GITTMP'
git config --replace-all filter.mixedtext.smudge 'GITTMP=$(mktemp);TYPE=$( tee $GITTMP|file -b --mime-encoding - ); cat $GITTMP | iconv -sc -f utf-8 -t $TYPE; rm -f $GITTMP'
git config --replace-all filter.mixedtext.required true

My .gitattributes file looks like this:

*.txt filter=mixedtext
*.ps1 filter=mixedtext
*.sql filter=mixedtext

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文