.gitattributes 使用 '* text=auto' 和过滤器

.gitattributes using '* text=auto' with filters

在跨平台项目中,为所有文本文件“* text=auto”和[配置CRLF规范化的正确方法是什么? =41=] 和 'clean' 过滤器 某些文件 '*.h filter=myfilter'?

示例:

# my .gitattributes
* text=auto           # in case people don't have core.autocrlf set
*.h filter=myfilter   # filter for header files

添加 *.h filter=myfilter 后,我收到如下警告:

warning: LF will be replaced by CRLF in foo.h.
The file will have its original line endings in your working directory.

如果我删除 *.h filter=myfilter,警告就会消失。为什么?此行是否为 *.h 文件禁用 CRLF 规范化

更新

关于警告,过滤器使用 sed 替换文件头注释中的标签。当 运行 on windows sed 正在将 CRLF 转换为 LF。这就是警告的来源。解决办法是运行sed二进制模式(--binary).

一些实验会产生相当混乱的结果。

The gitattributes documentation 预先说明:

When more than one pattern matches the path, a later line overrides an earlier line. This overriding is done per attribute.

(强调我的)这清楚地表明,虽然 *.h filter=myfilter 覆盖了 filter 设置的任何早期匹配,但它应该 而不是 影响任何早期 * text=...设置。

实际的入住和退房流程似乎很好:遵守前面的* text=<whatever>

然而,其他命令似乎将 filter 视为覆盖 text。 (这似乎是警告的来源。)

在这种情况下,您可以通过以下方式解决问题:

*.h text=auto filter=myfilter

但总的来说,这似乎违反了记录的行为。