Git 中有代码可以detect文件是文本还是二进制。
如果文件的前面有很多零 (ASCII NUL) 字节,则该文件被视为二进制文件。对于其他一些二进制模式也是如此。
默认情况下,Git 使用此代码来决定是否向您显示差异,当git diff
检测到某些文件中的某些更改。如果文件看起来是二进制文件,Git 会说“二进制文件不同”(默认情况下,您可以让它打印可用的差异,并且git format-patch
例如,强制该行为)。否则,该文件将显示为文本,因此您将获得常规差异。
Git also使用此代码text=auto
in .gitattributes
, but not for text
-没有-=auto
. So:
* text=auto eol=<whatever>
tells Git: Every time you extract the file from the index to the work-tree, apply the detection code to the file. If the detection code claims that the file is a text file, apply the end of line conversions while rehydrating the freeze-dried copy of the file from the index into the usable form in the work-tree. If the detection code claims that the file is binary, leave it alone.1
相比之下,* text eol=<whatever>
告诉 Git:每次将文件重新水合到工作树中时,请应用行尾转换。Git 2.10 版本之前的 bug 是* text=auto
不小心的意思* text
代替* text=auto
.
1Since the text-detection sometimes—though not all that often—misfires on (e.g.) .jpg
image files, it's not wise to depend on text=auto
. But it works most of the time.