我可以让git识别一个UTF-16文件作为文本吗? [英] Can I make git recognize a UTF-16 file as text?

查看:173
本文介绍了我可以让git识别一个UTF-16文件作为文本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git中跟踪一个虚拟PC虚拟机文件(* .vmc),在做了一个更改git后,将该文件标识为二进制,并且不会对我进行区分。我发现文件是用UTF-16编码的。

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?

我在Cygwin下使用git,core.autocrlf设置为false。我可以在UNIX下使用mSysGit或git。

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

推荐答案

我一直在努力解决这个问题, (对我来说)一个完美的解决方案:

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 使用与 git diff 相同的参数,但运行您选择的diff程序,而不是内置的GNU diff 。所以选择一个多字节感知的差异(在我的情况下,在差异模式下, vim ),只需使用 git difftool git diff

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.

找到difftool太长才能输入?没问题:

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

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

Git岩石。

这篇关于我可以让git识别一个UTF-16文件作为文本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆