如何强制 git 在 windows 下使用 LF 而不是 CR+LF? [英] How do I force git to use LF instead of CR+LF under windows?
问题描述
我想强制 git 在 Windows 下只使用 LF
而不是 CR+LF
签出文件.我检查了两个配置选项,但找不到正确的设置组合.
我希望它将所有文件转换为 LF
并将 LF
保留在文件上.
备注:我使用了 autocrlf = input
但这只是在您提交文件时修复文件.我想强制它使用 LF
获取它们.
可能我不太清楚:存储库已经在使用 LF
但使用 msysgit 检出的文件正在使用 CR+LF
并且我想强制 msysgit使用 LF
获取它们:强制 Unix 行结束.
>git config --list |grep crlfcore.autocrlf=输入
OP 在他的问题中添加:
<块引用>使用 msysgit 检出的文件正在使用 CR+LF
,我想强制 msysgit 使用 LF
第一个简单的步骤仍然是在 .gitattributes
文件中:
# 2010*.txt -crlf# 2020*.txt 文本 eol=lf
(如 在评论中注明 由孙子,指的是.gitattributes
行尾转换),以避免任何CRLF
转换具有正确 eol
的文件.
和 我一直建议 git config --global core.autocrlf false
禁用任何转换(适用于所有版本化文件)
自 Git 2.16(2018 年第一季度)起,您可以使用 git add --renormalize .
立即应用那些 .gitattributes
设置.
但第二个更强大的步骤涉及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 force msysgit to get them withLF
A first simple step would still be in a .gitattributes
file:
# 2010
*.txt -crlf
# 2020
*.txt text eol=lf
(as noted in the comments by grandchild, referring to .gitattributes
End-of-line conversion), to avoid any CRLF
conversion for files with correct eol
.
And I have always recommended git config --global core.autocrlf false
to disable any conversion (which would apply to all versioned files)
See Best practices for cross platform git config?
Since Git 2.16 (Q1 2018), you can use git add --renormalize .
to apply those .gitattributes
settings immediately.
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屋!