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

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

问题描述

我有一些.sql文件,我第一次推到github上。然而,当我看到提交它说:

  BINWebRole / Sql / Database.sql查看
二进制文件未显示

有人可以告诉我为什么它说Binary file not shown / b>

解决方案

这个扩展本身并不足以让Github看到它是否是一个文本文件。

So它必须看看它的内容。



正如为什么Git将这个文本文件当作一个二进制文件?,它的内容可能不包含足够的ascii字符来猜测它是文本文件。



您可以使用 .gitattributes文件显式指定 .sql 应该是一个文本,而不是二进制文件。

  .sql diff 

由于 kostix a>加入注释:如果这些文件是由Microsoft SQL Management Studio生成的(或者在版本中调用的任何文件),那么


您使用的MS SQL Server管理工具),它保存的文件以UCS-2(或UTF-16)编码 - 两字节编码,这实际上不是Git眼中的文本。


您可以在 Git说二进制文件a ...和b ...不同for * .reg 文件



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


为什么Git会将我的文件标记为二进制文件?答案是因为它在文件的前8000个字符内有一个NUL(0)字节。

通常情况下,这是因为文件被保存为UTF-8以外的内容。所以,它可能被保存为UCS-2,UCS-4,UTF-16或UTF-32。所有这些在使用ASCII字符时都嵌入了NUL字符







As Neo 提及注释中)为什么Git将这个文本文件当作一个二进制文件?):

lockquote

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


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"

解决方案

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

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.

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

.sql diff

As kostix adds in the comments:

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

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

As mentioned in "Set file as non-binary in git":

"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


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

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天全站免登陆