diff 和 diff=astextplain 有什么区别?

What is the difference between diff and diff=astextplain?

谁能帮帮我。我正在使用 Git (GitHub) 并试图决定在 gitattributes 中将我的 *.sql 文件设置为什么。我见过有人用

*.sql diff=astextplain
*.sql diff
*.sql text=auto

有人建议我将此设置为第二个选项,但我只是想知道它与其他两个选项之间有什么区别。

TL;DR

  • diff=astextplain(仅限msysGit):转换那些文件(前提是它们的扩展名是*.doc*.pdf*.rtf等。 ) 在生成差异之前转换为文本格式。
  • diff:将这些文件视为纯文本以生成它们的差异。
  • text=auto:自动规范化 Git.
  • 认为是文本文件的文件中的 EOL 字符(到 LF)

更多详情

diff=astextplain

字符串值astextplain不是Git核心的一部分:事实上,运行

git grep "astextplain"

Git 项目库中 returns 没有。据我所知,它是 msysGit 附带的 shell 脚本 并允许您转换

等文件
  • Word 文档,
  • PDF,
  • RTF

在生成差异之前转换为文本格式。

diff

根据 gitattributes man page:

The attribute diff affects how Git generates diffs for particular files. [...]

A path to which the diff attribute is set is treated as text, even when they contain byte values that normally never appear in text files, such as NUL.

text=auto

根据 gitattributes man page:

When text is set to "auto", the path is marked for automatic end-of-line normalization. If Git decides that the content is text, its line endings are normalized to LF on checkin.