Git默认将哪些文件类型视为二进制文件?[重复]

mspsb9vt  于 9个月前  发布在  Git
关注(0)|答案(1)|浏览(87)

此问题在此处已有答案

How to determine if Git handles a file as binary or as text?(9个回答)
13天前关闭
我知道如何使用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

字符串
这是否意味着默认情况下图像不被视为二进制文件?
编辑:理论上也可能涉及一些“猜测”算法,但我还没有找到任何细节。

pb3skfrl

pb3skfrl1#

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(+))

字符串

相关问题