为什么git认为我的.sql文件是二进制文件?

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

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

有人可以告诉我为什么这是说“二进制文件未显示”

扩展本身不足以让Github看到它是否是一个文本文件。
所以它必须看它的内容。

而如“Why does Git treat this text file as a binary file?”所述,其内容可能不包含足够的ascii字符来猜测它是文本文件。

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

.sql diff

由于kostix 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

您可以在“Git says “Binary files a… and b… differ” on for *.reg files”中看到一个例子

如“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

正如Neo提到in the comments(和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.

翻译自:https://stackoverflow.com/questions/28145687/why-does-git-think-my-sql-file-is-a-binary-file

转载注明原文:为什么git认为我的.sql文件是二进制文件?