默认情况下,Git 将哪些文件类型视为二进制文件?

Bor*_*ard 5 git

我知道如何使用 gitattributes 强制 Git 将例如 JPEG 文件视为二进制文件,但实际上 Git 的默认二进制文件列表是什么?或者有吗?我在我的系统上发现了似乎是系统范围的 gitattributes 文件,这是它的内容:

*.doc   diff=astextplain
*.DOC   diff=astextplain
*.docx  diff=astextplain
*.DOCX  diff=astextplain
*.dot   diff=astextplain
*.DOT   diff=astextplain
*.pdf   diff=astextplain
*.PDF   diff=astextplain
*.rtf   diff=astextplain
*.RTF   diff=astextplain
Run Code Online (Sandbox Code Playgroud)

这是否意味着默认情况下图像不被视为二进制文件?

编辑:理论上也可能涉及一些“猜测”算法,但我还没有找到任何细节。

use*_*247 0

git 中没有默认的二进制文件列表。

确实有一个简单的算法:

如果前 8000 个字节中的任何一个包含 NULL 字符,则将其视为二进制文件。

您可以在此处阅读本文撰写时最新的 git 稳定版本 (2.43)的确切代码。

我能想出的最短的证明来证明这一点:

$ git init
$ # A file with just a NULL character
$ echo -e '\x00' > bin 
$ # A file with just the ascii A character
$ echo -e 'A' > ascii 
$ # The last of 8000s first character is a NULL
$ (perl -e 'print "A" x 7999' ; echo -e "\x00") > long-bin 
$ # This one, the null is the 8001s character
$ (perl -e 'print "A" x 8000' ; echo -e "\x00") > long-ascii 
$ git commit --allow-empty --allow-empty-message
$ git stash -u
$ git stash show -u
git stash show -u
 ascii      |   1 +
 bin        | Bin 0 -> 2 bytes
 long-ascii |   1 +
 long-bin   | Bin 0 -> 8001 bytes
 4 files changed, 2 insertions(+))
Run Code Online (Sandbox Code Playgroud)