search

Home  >  Q&A  >  body text

git 自动换行在WINDOWS和LINUX下的区别

最近在windows下面最了个项目用git来管理,git add .的时候一直报错 LF will be replaced by CRLF,网上的大部分答案都是git config --global core.autocrlf false,禁用自动换行,这样做确实可以让我在这个项目中add了

但是问题是,另一项目(从mac下拉的代码),做管理的时候必须要把它设置成true才可以


我现在脑子有点瓦特,能不能哪位大神仔细讲一下,这个过程到底是发生了什么?

淡淡烟草味淡淡烟草味2761 days ago813

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-05-02 09:34:11

    Um, are you using Baidu? . . So you don’t know the cause of the problem at all, it has nothing to do with automatic line wrapping

    windows newline character: CRLF Linux/UNIX newline character: LF
    So of course you need to convert the carriage return character from windows to UNIX.

    git config --global core.autocrlf false

    Turn off line break conversion function

    git config --global core.autocrlf true

    It works as follows:
    Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index
    From the official documentation

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-02 09:34:11

    Since git was exclusive to Linux at first, line breaks have always been LF in Linux. If a project team has Linux and Windows users, then the line breaks should be unified. Of course, general files should be unified as LF. After autocrlf is turned on, the local files of Windows users will still be CR LF, automatically converted to LF when submitted.

    ps: Since Windows is widely used in China, it is very possible to change Windows-specific files to LF line breaks, such as bat batch scripts. In this way, the files downloaded from github will lose the CR line breaks, resulting in the inability to run.

    This setting item is redundant. It is generally recommended to turn it off and manually ensure that the line breaks are consistent. Generally, current IDEs can display multiple line break styles normally, and LF can also be displayed normally under Windows. As long as you don't edit the code with Windows Notepad, there will be no CR LF style line breaks.

    reply
    0
  • Cancelreply