为什么 Git 将此文本文件视为二进制文件? [英] Why does Git treat this text file as a binary file?

查看:26
本文介绍了为什么 Git 将此文本文件视为二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么 git 会告诉我这个?

I wonder why git tells me this?

$ git diff MyFile.txt
diff --git a/MyFile.txt b/MyFile.txt
index d41a4f3..15dcfa2 100644
Binary files a/MyFile.txt and b/MyFile.txt differ

它们不是文本文件吗?

我检查了 .gitattributes 并且它是空的.为什么我会收到此消息?,我不能再像以前那样获得差异了

I have checked the .gitattributes and it is empty. Why I am getting this message ?, I cannot get diffs as I use to anymore

添加:

我注意到文件权限中有一个@,这是什么?,这可能是原因吗?

I've noticed there is an @ in the file permissions, what is this ?, Could this be the reason ?

$ls -all
drwxr-xr-x   5 nacho4d  staff    170 28 Jul 17:07 .
drwxr-xr-x  16 nacho4d  staff    544 28 Jul 16:39 ..
-rw-r--r--@  1 nacho4d  staff   6148 28 Jul 16:15 .DS_Store
-rw-r--r--@  1 nacho4d  staff    746 28 Jul 17:07 MyFile.txt
-rw-r--r--   1 nacho4d  staff  22538  5 Apr 16:18 OtherFile.txt

推荐答案

这只是意味着当 git 检查文件的实际内容时(它不知道任何给定的扩展名不是二进制文件——如果你想明确地告诉它,你可以使用属性文件——参见手册页).

It simply means that when git inspects the actual content of the file (it doesn't know that any given extension is not a binary file - you can use the attributes file if you want to tell it explicitly - see the man pages).

检查了文件的内容后,它发现了一些不是基本 ascii 字符的内容.作为 UTF16,我希望它会有有趣"的字符,所以它认为它是二进制的.

Having inspected the file's contents it has seen stuff that isn't in basic ascii characters. Being UTF16 I expect that it will have 'funny' characters so it thinks it's binary.

如果你的文件有国际化 (i18n) 或扩展字符格式,有多种方法可以告诉 git.我对设置的确切方法还不够了解-您可能需要 RT[Full]M ;-)

There are ways of telling git if you have internationalisation (i18n) or extended character formats for the file. I'm not sufficiently up on the exact method for setting that - you may need to RT[Full]M ;-)

快速搜索找到的 SO can-i-make-git-recognize-a-utf-16-file-as-text 这应该会给你一些线索.

a quick search of SO found can-i-make-git-recognize-a-utf-16-file-as-text which should give you a few clues.

这篇关于为什么 Git 将此文本文件视为二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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