【问题标题】:How git is guessing content type for purposes of end-of-line normalization?为了行尾标准化,git 如何猜测内容类型?
【发布时间】:2019-07-16 05:08:56
【问题描述】:

根据the documentation on .gitattributes,text 启用行尾归一化:

text

在路径上设置文本属性可启用行尾规范化并将路径标记为文本文件。在不猜测内容类型的情况下进行行尾转换。

我有项目中使用的扩展名列表(git ls-tree -r HEAD --name-only | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u 用于查找文件类型 - 来自 How can I find all of the distinct file extensions in a folder hierarchy?)。

有没有办法检查 git 将每个扩展正确识别为二进制/文本?是否需要明确指定文件类型,或者 Git 通常处理得很好?

【问题讨论】:

  • Git 本身并没有以这种方式使用扩展。 您可以通过将它们列在.gitattributes 文件中来使用它们,但默认情况下,Git 只是尝试根据文件中的数据来确定文件是二进制文件还是文本文件。

标签: git normalization gitattributes end-of-line


【解决方案1】:

你可以使用类似的东西:

file --mime package.json
# text file will print:
package.json: text/plain; charset=us-ascii


# binary file will print
file --mime logo.png
logo.png: image/png; charset=binary

【讨论】:

  • 所以 Git 的行为基于 file 命令?它将在 Windows 上使用什么?
  • 简化一下,git对windows也有同样的机制
猜你喜欢
  • 2015-05-02
  • 2013-01-16
  • 1970-01-01
  • 2020-08-24
  • 1970-01-01
  • 2016-04-13
  • 1970-01-01
  • 2010-11-10
相关资源
最近更新 更多