gitdiffutf-16git-gui

git gui - can it be made to display UTF-16?


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.


Solution

  • 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.