在 Windows 中覆盖 .gitattributes text=auto

ana*_*nik 6 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.
Run Code Online (Sandbox Code Playgroud)

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

在项目根目录中,我发现.gitattributes了以下内容:

# Auto detect text files and perform LF normalization
* text=auto
Run Code Online (Sandbox Code Playgroud)

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

Jos*_*cki 7

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

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

gitattributes请参阅和属性text文档。

另请注意 core.eol属性eol


Dav*_*sch 6

.gitattributes覆盖所有配置设置,所以它真的不能被覆盖;可以这么说,它是“覆盖程序”。虽然您可以简单地删除该行,但如果其他开发人员的计算机上有core.autocrlf=true. 所以最好的办法是将以下行添加到.gitattributes: * -text。这将禁用所有文件的 CRLF 处理。

  • 如果 GIT 有一些选项可以完全关闭 EOL 转换,而不管 .gitattributes 文件如何,那就太好了。就我而言,.gitattributes 文件由 RE 维护,我无法更改它,但我绝对希望仅使用 LF 将所有文件保存在我的电脑上。 (3认同)