zoukankan      html  css  js  c++  java
  • Git换行符是如何精确控制的

    Git换行符是如何精确控制的

    Checkout Windows-style, commit Unix-style

    Git will convert LF to CRLF when checking out text files. When committing text files, CRLF will be converted to LF. For cross-platform projects, this is the recommended setting on Windows ("core.autocrlf" is set to "true")

    Checkout as-is, commit Unix-style

    Git will not perform any conversion when checking out text files. When committing text files, CRLF will be converted to LF. For cross-platform projects this is the recommended setting on Unix ("core.autocrlf" is set to "input").

    Checkout as-is, commit as-is

    Git will not perform any conversions when checking out or committing text files. Choosing this option is not recommended for cross-platform projects ("core.autocrlf" is set to "false")

    官方文档

    Formatting and Whitespace
    Formatting and whitespace issues are some of the more frustrating and subtle problems that many developers encounter when collaborating, especially cross-platform. It’s very easy for patches or other collaborated work to introduce subtle whitespace changes because editors silently introduce them, and if your files ever touch a Windows system, their line endings might be replaced. Git has a few configuration options to help with these issues.

    core.autocrlf
    If you’re programming on Windows and working with people who are not (or vice-versa), you’ll probably run into line-ending issues at some point. This is because Windows uses both a carriage-return character and a linefeed character for newlines in its files, whereas Mac and Linux systems use only the linefeed character. This is a subtle but incredibly annoying fact of cross-platform work; many editors on Windows silently replace existing LF-style line endings with CRLF, or insert both line-ending characters when the user hits the enter key.

    Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the core.autocrlf setting. If you’re on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code:

    $ git config --global core.autocrlf true

    If you’re on a Linux or Mac system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:

    $ git config --global core.autocrlf input


    This setup should leave you with CRLF endings in Windows checkouts, but LF endings on Mac and Linux systems and in the repository.

    If you’re a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to false:

    $ git config --global core.autocrlf false

     

     

  • 相关阅读:
    jsp%不能解析
    hibernate映射数据库时@ManyToOne和@OneToMany
    PSP需求分析文档
    医院挂号系统前景与范围文档
    PSP个人软件开发工具需求分析文档
    英雄联盟战队管理系统项目前景与范围文档
    在学习抛出异常的过程中,关于错误信息 TypeError: exceptions must derive from BaseException 的原因
    python面向对象__slots__变量的运用
    初学过程中,对于python if__name__=='main'的作用
    使用C模拟面向对象实现如java的LinkedList集合(好精彩)
  • 原文地址:https://www.cnblogs.com/pugang/p/8588918.html
Copyright © 2011-2022 走看看