如何强制git在Windows下使用LF而不是CR + LF? [英] How do I force git to use LF instead of CR+LF under windows?

查看:139
本文介绍了如何强制git在Windows下使用LF而不是CR + LF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想强制git在Windows下使用 LF 而不是 CR + LF 签出文件。我检查了两个配置选项,但我无法找到正确的设置组合。



我希望它将所有文件转换为 LF 并保留 LF 这些文件。



备注:我使用 autocrlf = input 但这只是在你提交它们时修复这些文件。我想强制它使用 LF



可能我没那么清楚:存储库是已经使用 LF ,但使用msysgit签出的文件使用 CR + LF ,我想强制msysgit获取它们使用 LF 强制Unix行尾

 > git config --list | grep crlf 
core.autocrlf = input


解决方案

OP在他的问题中加入:


使用msysgit签出的文件使用 CR + LF ,并且我想伪造msysgit以使用 LF




第一个简单步骤仍然在 .gitattributes 文件中:

  * .txt -crlf 

,可以避免使用正确的eol文件进行crlf转换。



请参阅 跨平台git配置的最佳实践






但第二个更强大的步骤涉及 gitattribute过滤器驱动程序并添加涂抹步骤





每当你更新你的工作树时,一个脚本只能用于你在 .gitattributes ,强制执行 LF eol 和任何其他格式化选项。

如果 clear 脚本没有做任何事情,你会(在提交之后)转换你的文件,使用你需要的格式。


I want to force git to checkout files under Windows using just LF not CR+LF. I checked the two configuration options but I was not able to find the right combination of settings.

I want it to convert all files to LF and keep the LF on the files.

Remark: I used autocrlf = input but this just repairs the files when you commit them. I want to force it to get them using LF.

Probably I wasn't so clear: the repository is already using LF but the files checked out using msysgit are using CR+LF and I want to force msysgit to get them with LF: forcing Unix line endings.

>git config --list | grep crlf
core.autocrlf=input

解决方案

The OP added in his question:

the files checked out using msysgit are using CR+LF and I want to forge msysgit to get them with LF

A first simple step would still be in a .gitattributes file:

*.txt -crlf

, to avoid any crlf conversion for files with correct eol.

See Best practices for cross platform git config?


But a second more powerful step involves a gitattribute filter driver and add a smudge step

Whenever you would update your working tree, a script could, only for the files you have specified in the .gitattributes, force the LF eol and any other formatting option you want to enforce.
If the "clear" script doesn't do anything, you will have (after commit) transformed your files, applying exactly the format you need them to follow.

这篇关于如何强制git在Windows下使用LF而不是CR + LF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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