在Windows中覆盖.gitattributes text = auto

时间:2015-06-22 11:22:11

标签: windows git gitattributes core.autocrlf

这非常不直观:

C:\python-tdl\examples\termbox>git config core.autocrlf
false

C:\python-tdl\examples\termbox>git commit termbox.py
warning: LF will be replaced by CRLF in examples/termbox/termbox.py.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in examples/termbox/termbox.py.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in examples/termbox/termbox.py.
The file will have its original line endings in your working directory.
Aborting commit due to empty commit message.

根据core.autocrlf=false的各种媒体,根本不应该进行换行转换。

在项目根目录中,我发现了.gitattributes行:

# Auto detect text files and perform LF normalization
* text=auto

如果我发表评论,警告就会消失。问题 - 如何自动覆盖此.gitattibutes设置?

2 个答案:

答案 0 :(得分:3)

.gitattributes会覆盖所有配置设置,因此无法覆盖;它是" overrider,"可以这么说。虽然您可以简单地删除该行,但这会导致其他开发人员的行为不一致。机器如果有core.autocrlf=true。因此,最好的办法是将以下行添加到.gitattributes* -text。这将禁用所有文件的CRLF处理。

答案 1 :(得分:1)

至少在现代版本的git中,.git/info/attributes(或$GIT_DIR/info/attributes)会覆盖.gitattributes进行本地配置。

使用* !text来使用core.autocrlf的值,或者使用* -text来强制不进行转换。

请参阅gitattributesthe text attribute的文档。

也请注意: core.eolthe eol attribute