我自己的设置是:

[core]
autocrlf = false
[core]
safecrlf = true

取消自动转换CRLF(上图中选的是commit as is),但是有提交前混用检查

本人用的是WINDOWS下的PHPSTORM开发的PHP


遇到这两个错误,是因为Git的换行符检查功能。

core.safecrlf

Git提供了一个换行符检查功能(core.safecrlf),可以在提交时检查文件是否混用了不同风格的换行符。这个功能的选项如下:

  • false - 不做任何检查
  • warn - 在提交时检查并警告
  • true - 在提交时检查,如果发现混用则拒绝提交

建议使用最严格的 true 选项。

core.autocrlf

假如你正在Windows上写程序,又或者你正在和其他人合作,他们在Windows上编程,而你却在其他系统上,在这些情况下,你可能会遇到行尾结束符问题。这是因为Windows使用回车和换行两个字符来结束一行,而Mac和Linux只使用换行一个字符。虽然这是小问题,但它会极大地扰乱跨平台协作。

Git可以在你提交时自动地把行结束符CRLF转换成LF,而在签出代码时把LF转换成CRLF。用core.autocrlf来打开此项功能,如果是在Windows系统上,把它设置成true,这样当签出代码时,LF会被转换成CRLF

$ git config --global core.autocrlf true

Linux或Mac系统使用LF作为行结束符,因此你不想 Git 在签出文件时进行自动的转换;当一个以CRLF为行结束符的文件不小心被引入时你肯定想进行修正,core.autocrlf设置成input来告诉 Git 在提交时把CRLF转换成LF,签出时不转换

$ git config --global core.autocrlf input

这样会在Windows系统上的签出文件中保留CRLF,会在Mac和Linux系统上,包括仓库中保留LF。

如果你是Windows程序员,且正在开发仅运行在Windows上的项目,可以设置false取消此功能,把回车符记录在库中

$ git config --global core.autocrlf false

 

转自:http://blog.csdn.net/feng88724/article/details/11600375


git 处理和修改行结束符(CRLF和LF)

本文转载自http://www.tuicool.com/articles/IJjQVb

目录:

  1. 什么是CRLF和LF
  2. 为什么要探究CRLF和LF
  3. 三种方式处理的不同
  4. 更多
  5. 参考文献

1、什么是CRLF和LF

CRLF 是carriagereturnlinefeed的缩写。中文意思是回车换行。

LF是line feed的缩写,中文意思是换行。

2、为什么要探究CRLF和LF

在学习git软件,安装git到configuring the lien ending conversion时,有三个选项。

a. Checkout Windows-style,commit Unix-style line endings.

b.Checkout as-is,commit Unix-style line endings.

c.Checkout as-is,commit as-is line endings.

这里面讲到了做两个操作(Checkout,Commit)的三种处理line endings的操作(Windows-style,Unix-style,As-is)。

为什么会出现这三种处理line endings(行尾结束符)呢?在Git的帮助页面给出了很好的解释。

Reference From:https://help.github.com/articles/dealing-with-line-endings

If you're using Git to collaborate with others on GitHub, ensure that Git isproperly configured to handle line endings.

Every time you press return on your keyboard you're actuallyinserting an invisible character called a line ending . Historically, differentoperating systems have handled line endings differently.

When you view changes in a file, Git handles line endings in its own way.Since you're collaborating on projects with Git and GitHub, Git mightproduce unexpected results if, for example, you're working on a Windows machine,and your collaborator has made a change in OS X.

意思很好理解,就不翻译了。重视由于历史的原因,各种不同的操作系统在处理行尾结束符采取了不同的处理方法。而Git和GitHub

3、三种方式处理的不同

CRLF->Windows-style

LF->Unix Style

CR->Mac Style

CRLF表示句尾使用回车换行两个字符(即我们常在Windows编程时使用"\r\n"换行)

LF表示表示句尾,只使用换行.

CR表示只使用回车.

4、在Git中如何转换?

在Git通过下面的命令配置

$git config --global core.autocrlf true
# Configure Git on Windows to properly handle line endings

解释:core.autocrlf是git中负责处理line endings的变量,可以设置三个值--true,inout,false.

设置成三个值会有什么效果呢?

If core.autocrlf is set to true, that means that any time you add a file to the git repo that git thinks is a text file, it will turn all CRLF line endings to just LF before it stores it in the commit.。

设置为true,添加文件到git仓库时,git将其视为文本文件。他将把crlf变成lf。【2】

If core.autocrlf is set to false, no line-ending conversion is ever performed, so text files are checked in as-is. This usually works ok。【2】

设置为false时,line-endings将不做转换操作。文本文件保持原来的样子。

设置为input时,添加文件git仓库石,git把crlf编程lf。当有人Check代码时还是lf方式。因此在window操作系统下,不要使用这个设置。

这是参考文献2给的解释希望能帮助大家。

Yet another way to show how autocrlf works

1) true:             x -> LF -> CRLF
2) input: x -> LF -> LF
3) false: x -> x -> x

where x is either CRLF (windows-style) or LF (unix-style) and arrows stand for

file to commit -> repository -> checked out file

更多:

更为复杂的配置命令见网站:https://www.kernel.org/pub/software/scm/git/docs/git-config.html

关于LF和CRLF讨论见:http://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf

You can also provide a special --global flag, which makes Git usethe same settings for line endings across every local Git repository on your computer.

--------------------------------------------------------------------------------------------------------------------------------------------------------

本文转载自https://my.oschina.net/moooofly/blog/228467

解决不同平台下结束符差别导致的各种问题,需要通过设置  core.autocrlf 来搞定。两种可能遇到的提示信息:

warning: LF will be replaced by CRLF

fatal: CRLF would be replaced by LF

假如你正在 Windows 上写程序,又或者你正在和其他人合作,他们在 Windows 上编程,而你却在其他系统上,在这些情况下,你可能会遇到行尾结束符问题。这是因为 Windows 使用回车和换行两个字符来结束一行,而 Mac 和 Linux 只使用换行一个字符。虽然这是小问题,但它会极大地扰乱跨平台协作。

Git 可以在你提交时,自动地把行结束符 CRLF 转换成 LF,而在签出代码时把 LF 转换成 CRLF 。用 core.autocrlf 来打开此项功能,如果是在Windows 系统上,把它设置成 true,这样当签出代码时,LF 会被转换成 CRLF:

git config --global core.autocrlf true

Linux 或 Mac 系统使用 LF 作为行结束符,因此你不想 Git 在签出文件时进行自动的转换;当一个以 CRLF 为行结束符的文件不小心被引入时,你肯定想进行修正,把 core.autocrlf 设置成 input 来告诉 Git 在提交时把 CRLF 转换成 LF,签出时不转换:

git config --global core.autocrlf input

参考上面的配置方法,你就可以在 Windows 系统上,签出文件时保留 CRLF,而在 Mac 和 Linux 系统上,包括仓库中,保留 LF 。

如果你是 Windows 程序员,且正在开发仅运行在 Windows 上的项目,可以设置 false 取消此功能,把回车符记录在库中:

git config --global core.autocrlf false

[git] warning: LF will be replaced by CRLF | fatal: CRLF would be replaced by LF[ git 处理和修改行结束符(CRLF和LF)]的更多相关文章

  1. [git] warning: LF will be replaced by CRLF | fatal: CRLF would be replaced by LF

    遇到这两个错误,是因为Git的换行符检查功能. core.safecrlf Git提供了一个换行符检查功能(core.safecrlf),可以在提交时检查文件是否混用了不同风格的换行符.这个功能的选项 ...

  2. git提交代码报:fatal: Unable to create 'E:/testGit/test/.git/index.lock': File exists.

    git提交代码报错,提示:fatal: Unable to create 'E:/testGit/test/.git/index.lock': File exists. 具体截图如下: 在.git目录 ...

  3. [GIT] warning: LF will be replaced by CRLF问题解决方法

    原文链接[http://michael-roshen.iteye.com/blog/1328142] 开发环境: 操作系统: windows xp ruby 1.9.2 rails 3.1.3 git ...

  4. 解决:git warning: LF will be replaced by CRLF in xxxx

    一. git add -A报错 在利用git add -A添加文件时,意外的发现报错了 报错信息中: LF:Line Feed 换行 CRLF:Carriage Return Line Feed  回 ...

  5. Git处理 行结束符

    Dealing with line endings (Windows) 如果你正在使用Git在GitHub上和别人协作的话,确保Git处理行结束符的配置已经正确配置了. 每次在键盘上按下return键 ...

  6. GitBook是一个命令行工具(Node.js库),我们可以借用该工具使用Github/Git和Markdown来制作精美的图书,但它并不是一本关于Git的教程哟。

    GitBook是一个命令行工具(Node.js库),我们可以借用该工具使用Github/Git和Markdown来制作精美的图书,但它并不是一本关于Git的教程哟. 支持输出多种格式 GitBook支 ...

  7. ssh: Could not resolve hostname git.*****-inc.com : Temporary failure in name resolution fatal: The remote end hung up unexpectedly

    问题出现的情景:使用git pull拉取开发的代码到测试服务器,报错: ssh: Could not resolve hostname git.****-inc.com : Temporary fai ...

  8. git提示error setting certificate verify locations以及fatal: unable to access 的解决办法

    z当使用git ------上传文件到GitHub上时!~~~出现了以下错误  :fatal: unable to access ' 可以采用以下解决方式: 修改GitHub上的地址格式=====ht ...

  9. Git 发生Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'.错误

    Git 发生 Unable to create 'D:/Model/test/.git/index.lock': File exists. Another git process seems to b ...

随机推荐

  1. Isolate-user-vlan技术白皮书

    http://www.h3c.com.cn/Products___Technology/Technology/LAN/Other_technology/Technology_book/200804/6 ...

  2. c++ 中反正单词用到了resize()

    resize(n) 调整容器的长度大小,使其能容纳n个元素.如果n小于容器的当前的size,则删除多出来的元素.否则,添加采用值初始化的元素. 题目如下: 151. Reverse Words in ...

  3. 玩adb和fastboot

    http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380143fd3d1027fa3c215cc790a1b18 ...

  4. linux mysql 链接数太小

    Data source rejected establishment of connection,  message from server: "Too many connections&q ...

  5. can be found for element 'tx:annotation-driven'

    错误描述: ERROR [ContainerBackgroundProcessor[StandardEngine[Catalina]]] (ContextLoader.java:308) - Cont ...

  6. Shiro 的 HelloWorld

    密码文件 [users] zhang=123 wang=123 测试 package org.zln.hello; import org.apache.log4j.LogManager; import ...

  7. BZOJ4531 && BJOI2014 trace

    #include<cstdio> #include<cctype> using namespace std ; struct state { int len ; int p ; ...

  8. Java中一些知识的归纳总结

    1.包装类型与基本数据类型的区别. Java语言是一个面向对象的语言,但是Java中的基本数据类型却是不面向对象的,这使得Java在实际使用时存在很多的不便,为了解决这个不足,在设计类时为每个基本数据 ...

  9. lucene、solr、nutch三者的关系

    lucene是一个做搜索用的类库. nutch和solr都是基于lucene的,二者都是可直接运行的应用程序: 直接在业务上使用lucene的倒是不太多见. solr主要提供了建立索引(用户可以直接p ...

  10. Drupal7导入语言包

    下载语言包 然后把包存放在profiles\standard\translations目录下,安装. 如果出现如下错误 1.错误有MySql数据库默认引擎innoDB引起,只要mysql\bin\my ...