为什么 git 认为我的 .sql 文件是二进制文件? [英] Why does git think my .sql file is a binary file?

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

问题描述

我有一些 .sql 文件,这是我第一次推送到 github.但是,当我查看提交时,它说:

I have some .sql files that I just for the first time pushed to github. However when I look at the commit it is saying:

BIN  WebRole/Sql/Database.sql View
Binary file not shown

谁能告诉我为什么说未显示二进制文件"

Can someone tell me why it's saying "Binary file not shown"

推荐答案

仅靠扩展名不足以让 GitHub 判断它是否是文本文件.
所以它必须看它的内容.

The extension alone isn't enough to GitHub to see if it is a text file.
So it has to look at its content.

并且如为什么 Git 将此文本文件视为二进制文件?"中所述,其内容可能不会包含足够的 ascii 字符来猜测它是文本文件.

And as mentioned in "Why does Git treat this text file as a binary file?", its content might not include enough ascii character to guess it is text file.

您可以使用 .gitattributes 文件明确指定 .sql 应该是文本,而不是二进制.

You can use a .gitattributes file to explicitly specify a .sql should be a text, not a binary.

*.sql diff

<小时>

2018 年更新:正如我在utf-8 编码不适用于 utf-8 编码文档"中提到的,Git2.18 .gitattributes 有一个新的 working-tree-encoding 属性.
所以,如 Rusi答案:


Update 2018: as I mention in "Utf-8 encoding not working on utf-8 encoded document", Git 2.18 .gitattributes has a new working-tree-encoding attribute.
So, as shown in Rusi's answer:

*.sql text working-tree-encoding=UTF-16LE eol=CRLF

<小时>

由于 kostix 添加了 评论:

如果这些文件是由 Microsoft SQL Management Studio(或您正在使用的 MS SQL Server 管理工具版本中的任何名称)生成的,则它保存的文件以 UCS-2(或 UTF-16)编码-- 一个两字节的编码,在Git眼里确实不是文本

if these files are generated by the Microsoft SQL Management Studio (or whatever it's called in the version of MS SQL Server's management tools you're using), the files it saves are encoded in UCS-2 (or UTF-16) -- a two-byte encoding, which is indeed not text in the eyes of Git

您可以在Git 说二进制文件 a... 和 b... 不同"中看到一个示例对于 *.reg 文件"

You can see an example in "Git says "Binary files a… and b… differ" on for *.reg files"

在 git 中将文件设置为非二进制文件"中所述:

为什么 Git 将我的文件标记为二进制文件?"答案是因为它在文件的前 8000 个字符内的某处看到了一个 NUL (0) 字节.
通常,发生这种情况是因为文件被保存为非 UTF-8 格式.因此,它很可能被保存为 UCS-2、UCS-4、UTF-16 或 UTF-32.所有这些在使用 ASCII 字符时都嵌入了 NUL 字符

"Why is Git marking my file as binary?" The answer is because it's seeing a NUL (0) byte somewhere within the first 8000 characters of the file.
Typically, that happens because the file is being saved as something other than UTF-8. So, it's likely being saved as UCS-2, UCS-4, UTF-16, or UTF-32. All of those have embedded NUL characters when using ASCII characters

<小时>

正如 Neo 提到的 在评论中(以及在为什么 Git 将此文本文件视为二进制文件?):


As Neo mentions in the comments (and in Why does Git treat this text file as a binary file?):

您可以通过从文件"菜单的高级保存选项"菜单项中选择带签名的 UTF-8"编码,将 SSMS 中保存的文件的编码更改为 UTF-8.

You can change the encoding of a saved file in SSMS to UTF-8 by selecting encoding 'UTF-8 with signature' from the 'Advanced Save Options' menu item in the File menu.

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

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