gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:39:21 24 4
gpt4 key购买 nike

我有一些 .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

2018 年更新:正如我在“Utf-8 encoding not working on utf-8 encoded document”中提到的,Git 2.18 .gitattributes 有一个新的 working-tree-encoding 属性。
因此,如 Rusianswer 所示:

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

正如 kostixthe 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.

关于git - 为什么 git 认为我的 .sql 文件是二进制文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28145687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com