gitunicodecharacter-encodingdiffutf-16

Can I make git recognize a UTF-16 file as text?


I'm tracking a Virtual PC virtual machine file (*.vmc) in git, and after making a change git identified the file as binary and wouldn't diff it for me. I discovered that the file was encoded in UTF-16.

Can git be taught to recognize that this file is text and handle it appropriately?

I'm using git under Cygwin, with core.autocrlf set to false. I could use mSysGit or git under UNIX, if necessary.


Solution

  • I've been struggling with this problem for a while, and just discovered (for me) a perfect solution:

    $ git config --global diff.tool vimdiff      # or merge.tool to get merging too!
    $ git difftool commit1 commit2
    

    git difftool takes the same arguments as git diff would, but runs a diff program of your choice instead of the built-in GNU diff. So pick a multibyte-aware diff (in my case, vim in diff mode) and just use git difftool instead of git diff.

    Find "difftool" too long to type? No problem:

    $ git config --global alias.dt difftool
    $ git dt commit1 commit2
    

    Git rocks.