使用.gitattributes强制LF行结尾而不会丢失自动文本/二进制推断? [英] Force LF line endings using .gitattributes without losing automatic text/binary inference?

查看:269
本文介绍了使用.gitattributes强制LF行结尾而不会丢失自动文本/二进制推断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的.gitattributes文件中使用eol=LF,但是我希望它仅对 应用Git自动确定为文本文件的文件.

I would like to use eol=LF in my .gitattributes file, but I would like it to apply only to the files Git automatically determines to be text files.

我能找到的最好的办法是将特定的文件扩展名/glob定义为文本或二进制.这是不理想的,因为列表可能很大.我已经尝试过* text=auto eol=LF,但是eol=LF部分似乎覆盖了auto部分.

The best I could find is to define specific file extensions / globs as text or binary. This is not ideal as the list could be huge. I've tried * text=auto eol=LF, but the eol=LF part appears to override the auto part.

是否可以在不要求特定git config设置的情况下强制LF行结尾,并且不会丢失自动文本/二进制推断?

Can I force LF line endings without requiring specific git config settings, and without losing the automatic text/binary inference?

推荐答案

更新:@romkyns评论后,我重新检查了所有内容,发现我的解决方案略有错误.正确的是具有以下内容的.gitattributes文件:

Update: after @romkyns comment I rechecked everything and found my solution to be slightly incorrect. Correct would be a .gitattributes-file with the following content:

* text=auto

根据文档这可确保Git考虑的所有文件成为文本将在存储库中具有规范化(LF)的行尾.

原始答案:

您要在.gitattributes中编写的内容很简单:

What you want to write in your .gitattributes is as simple as this:

* text=auto
* text eol=lf

第一行告诉git自动检测文件类型(二进制或文本,无论如何都是git的默认行为,因此可以省略),第二行用LF处理所有检测到的文本文件(仅那些)的行尾行尾.

First line tells git to autodetect file types (binary or text, which is the default behavior of git anyway and therefore may be omitted), second line treats the line endings of all detected text files (and only those) with a LF end of line.

我用一些混合的二进制内容和一些带有CRLF结尾的文本文件测试了此设置,并获得了预期的转换为LF结尾.

I tested this setting with some mixed binary contents and some text files with CRLF ending and got the expected conversion to LF ending.

这篇关于使用.gitattributes强制LF行结尾而不会丢失自动文本/二进制推断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆