Git无法在带有LF的Linux上检出由CRLF存储的文件 [英] Git can't check out on Linux with LF a file that was stored with CRLF

查看:204
本文介绍了Git无法在带有LF的Linux上检出由CRLF存储的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 https://github.com/winlibs/libjpeg签出第三方项目"libjpeg" 在Linux上(这只是一个示例,实际上我在许多其他项目中也遇到相同的问题).我有以下Git线尾配置.

I am checking out a third party project "libjpeg" from https://github.com/winlibs/libjpeg on Linux (it is just one example, actually I have the same problem with many other projects as well). I have the following Git line endings configuration.

我仅配置了全局设置(设置为以LF行结尾的结帐):

I have only global settings configured (set to checkout with LF line endings):

$ git config --system -l | grep core
core.eol=lf
core.autocrlf=false

$ git config --global -l | grep core
core.eol=lf
core.autocrlf=false

没有关于行尾的本地(回购)设置.

There are no local (repo) settings regarding line endings.

我阅读了有关Git行尾配置的这篇文章:

I read this article about the Git line endings configuration: https://adaptivepatchwork.com/2012/03/01/mind-the-end-of-your-line and I think that my configuration should give me LF for all text files on Linux. However it does not work. I get CRLF instead in my workspace. For example:

~/gitclonetest/libjpeg$ file libjpeg.map
libjpeg.map: ASCII text, with CRLF line terminators
~/gitclonetest/libjpeg$ cat -v libjpeg.map
LIBJPEG_9.0 {^M
  global:^M
    *;^M
};^M

有人可以帮助我了解我所缺少的吗?我的目标是在Linux主机上将所有文本文件(用于任何项目)自动转换为LF.

Can someone help me to understand what I am missing? My goal is to have all text files (for any project) automatically be converted to LF when I clone it on Linux host.

更新:目标是将Git配置为在装有LF的Linux主机上签出,即使该文件是使用CRLF存储在存储库中的.

UPDATE: The goal is to configure Git to check out on Linux host with LF even if then file was stored with CRLF in the repository.

推荐答案

问题是您已将core.autocrlf设置为true.该文档中说明了以下内容:

The problem is that you have core.autocrlf set to true. The documentation says the following:

将此变量设置为"true"与在所有文件上将text属性设置为"auto"以及将core.eol设置为"crlf"相同.如果要在工作目录中包含CRLF行尾,并且存储库中包含LF行尾,请设置为true.

Setting this variable to "true" is the same as setting the text attribute to "auto" on all files and core.eol to "crlf". Set to true if you want to have CRLF line endings in your working directory and the repository has LF line endings.

您绝对不希望在Unix或Linux系统上将该变量设置为true.除非您使用Windows系统(甚至还有更好的选择),否则应将其设置为false.

You definitely don't want to set that variable to true on a Unix or Linux system; it should be set to false unless you're on a Windows system (and even then there are better alternatives).

这篇关于Git无法在带有LF的Linux上检出由CRLF存储的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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