git 的行结束符

  • CR (Carriage Return) 表示<回车>
  • LF (Line Feed) 表示<换行>

1. 不同系统的行结束符

系统名称 行结束符 意义 释义 git line endings选项
DOS / Windows \r\n CRLF '\r'是使光标移动到行首 '\n'是使光标下移一行 Windows-style
MacOS \r CR return As-is
UNIX / Linux \n LF newline Unix-style

2. 安装git时的三个选项

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

a. Checkout Windows-style,commit Unix-style line endings.(签出CRLF,提交签入是LF)

b.Checkout as-is,commit Unix-style line endings.(签出CR,提交签入是LF)

c.Checkout as-is,commit as-is line endings. (签出CR,提交签入是CR)

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

3. git软件的 line ending和操作系统的对应关系

  • CRLF->Windows-style

  • LF->Unix Style

  • CR->Mac Style

4. 如何转换git的行尾结束符(line ending)

  • 签入和签出是针对代码管理工具来说的,签出是在本地获取最新代码,签入是将最新代码上传到代码管理工具中
  • 控制git的行尾结束符的是 core.autocrlf 的配置
  • core.autocrlf 的值有三个 true false inout,
    • true: 添加到git仓库时,将把所有CRLF行结尾都变成LF 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.。
    • false:不会执行换行转换,按原样签入 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。
    • input:添加到git仓库时,将会把CRLF转换成LF。当有人Checkout(签出)代码时还是lf方式。因此在window操作系统下,不要使用这个设置
  • core.autocrlf 三个值的直观变化
    1. true: x -> LF -> CRLF
    2. input: x -> LF -> LF
    3. false: x -> x -> x
      file to commit -> repository -> checked out file
      要提交的文件->存储库->签出的文件

5. git 常用的配置命令

  • git config -l 查看已配置的内容
  • git config --global core.autocrlf true 修改 core.autocrlf 的值,需要在项目的根目录进行修改
相关推荐
趁你还年轻_2 小时前
记录一次git提交失败解决方案
git
关于不上作者榜就原神启动那件事5 小时前
git版本控制学习
git·学习
Cchaofan12 小时前
Git/GitLab日常使用的命令指南来了!
git·gitlab
可乐加.糖18 小时前
项目版本管理和Git分支管理方案
java·git·目标跟踪·gitlab·敏捷流程·源代码管理
wingaso19 小时前
[经验总结]删除gitlab仓库分支报错:错误:无法推送一些引用到“http:”
linux·数据仓库·git
ice___Cpu1 天前
Git - 1( 14000 字详解 )
大数据·git·elasticsearch
范纹杉想快点毕业2 天前
以项目的方式学QT开发(一)——超详细讲解(120000多字详细讲解,涵盖qt大量知识)逐步更新!
c语言·数据结构·c++·git·qt·链表·github
qq_653644462 天前
如何查看打开的 git bash 窗口是否是管理员权限打开
开发语言·windows·git·bash
tonngw2 天前
【Mac 从 0 到 1 保姆级配置教程 12】- 安装配置万能的编辑器 VSCode 以及常用插件
git·vscode·后端·macos·开源·编辑器·github
橄榄熊2 天前
Git 常用命令详解
git