git gui - can it be made to display UTF16?

后端 未结 3 1958
陌清茗
陌清茗 2021-01-03 09:56

Is there any way to make git gui display and show diffs for UTF16 files somehow?

I found some information, but this is mostly referring to the command l

3条回答
  •  迷失自我
    2021-01-03 09:59

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

提交回复
热议问题