zoukankan      html  css  js  c++  java
  • windows | 换行符 | windows换行符号和Unix换行符

    windows换行符号和Unix换行符

    前言

    Windows和Unix(MACOS,Linux)是完全不一样的操作系统

    macOS,Linux都是类Unix系统,所以他们存在Unix的配置习惯; 而 windows系统准确是DOS系统

    是全新的系统,Windows和Unix有着本质差别

    最近,使用git推送项目,遇到之前常见的问题,虽然不是很严重,但是确是影响视觉体验。

    image

    问题如下:

    The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in xxxxx.

    说的就是 “ 这个文件有它自己原始的行结束在工作区时,警告: LF被CRLF替换 在xxx文件”

    说道这,就需要了解 Unxi系统和Windows系统一些微妙的差距

    在电脑系统中,如果文件中的内容需要换行,一般是 ,这点在Unix系统是体现的

    然而在Windows系统上,出奇的多了一个


    认识概念

    1、符号

    换行符(LR): line feed简称

    回车符(CR): carriage return的简称

    换行和回车符实际在文件中的直观感受是这样:

    image

    是的

    在windows系统中,换行用CRLE, 回车+换行符

    在Unix系统中,换行用LF,即换行符

    2、自动转换

    core.autolf是什么?

    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.

    翻译:

    格式和空格经常是开发者在合作交流中遇到的烦人和容易忽视的问题,特别是在跨平台合作中,很容易采用微妙的空格对于补丁或者其他的合作的作品。因为编辑器会稍微采取这些措施,如果你曾经在windows平台创建文件,这些文件的行可能会被替换,Git有一些配置选项去帮助解决这些问题。

    所以core,autolf就是说,git会帮助自动的将CRLF转化为LF

    设置为true就是转换

    $ git config --global core.autocrlf true
    

    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 line feed character for newlines in its files, whereas Mac and Linux systems use only the line feed 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
    

    这里需要认清两个区域

    • Windows文件系统 和 git(Unix系统)

    如果是进行git操作,其实是涉及了Unix系统配置,Linux也是类Unix系统

    所以此时从Windows系统(工作区) ➡ Unix系统(暂存区(index)或者版本库(repository))会经历 CRLFLF的转变

    如果涉及从 git(此时指的是Unix系统配置) ➡ windows本地文件系统(此时指的是windows配置)

    会经历 LFCRLF的转变

    这是由编辑器决定的

    如果设置为

    $ git config --global core.autocrlf true
    

    则会git会根据你的git操作(git add, git commit等),转换 符号

    如果设置为

    $ git config --global core.autocrlf false
    

    则不自动转换

    如果是windows系统,在windows文件系统中是CRLF,提交到版本库,也是CRLF

    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
    

    详情: https://stackoverflow.com/a/5834094/12341467

    所以针对最初的问题:

    就是说原本在windows文件系统区域的文件存在Unix配置LF

    然后git add,git commit就会转换(替换)为CRLF

    The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in xxxxx.

    image

    相关文章:

    来源: 博客园
    作者: 茶哩哩
    文章: 转载请注明原文链接:https://www.cnblogs.com/martin-1/p/14862818.html

  • 相关阅读:
    ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(模拟+线段树)
    [转]Red Hat Linux相关产品iso镜像下载【百度云】
    VMware Workstation Pro 14 虚拟机安装教程
    POJ
    HDU
    HDU
    HDU
    HDU
    1087 有多少不同的值 (20 分)
    1088 三人行 (20 分)
  • 原文地址:https://www.cnblogs.com/martin-1/p/14862818.html
Copyright © 2011-2022 走看看