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

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

问题描述

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

可以教 git 识别此文件是文本并适当处理它吗?

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

解决方案

我已经为这个问题苦苦挣扎了一段时间,刚刚发现(对我来说)一个完美的解决方案:

$ git config --global diff.tool vimdiff # 或 merge.tool 也可以合并!$ git difftool commit1 commit2

git difftool 采用与 git diff 相同的参数,但运行您选择的 diff 程序而不是内置的 GNU diff.所以选择一个多字节感知的差异(在我的例子中,vim 在差异模式下)并且只使用 git difftool 而不是 git diff.

发现difftool"太长而无法输入?没问题:

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

Git 摇滚.

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.

解决方案

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.

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

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