简体   繁体   English

Git - Windows和Linux的行结尾

[英]Git - Windows AND linux line-endings

My main OS is windows 10. 我的主要操作系统是Windows 10。

I have an Ubuntu 14.04 box running in Vagrant that I develop my applications on. 我有一个在Vagrant中运行的Ubuntu 14.04盒子,我开发了我的应用程序。 The box is running SMB which gives me root file access to the Ubuntu server. 该框正在运行SMB,它为我提供了对Ubuntu服务器的根文件访问。

On the Ubuntu server I have my application files in a GIT repo with a gitlab server as the origin. 在Ubuntu服务器上,我将我的应用程序文件放在GIT仓库中,并以gitlab服务器为原点。

I run SourceTree on my windows machine that connects to the ubuntu GIT repo through the SMB share (so I assume it uses my Windows GIT installation). 我在我的Windows机器上运行SourceTree,通过SMB共享连接到ubuntu GIT仓库(所以我假设它使用我的Windows GIT安装)。

Git status on the ubuntu machine gives no changes. ubuntu机器上的Git状态不会发生任何变化。

Git status on Windows and SourceTree indicate that all the files have changed (because of the line endings). Windows和SourceTree上的Git状态表示所有文件都已更改(因为行结尾)。

What settings on which OS should I use in order to be able to use the same local repo on both Windows and Linux? 为了能够在Windows和Linux上使用相同的本地存储,我应该使用哪些操作系统设置?

On Windows: 在Windows上:

$ git config --global core.autocrlf true

On Linux: 在Linux上:

$ git config --global core.autocrlf input

Read more about Dealing with line endings 阅读更多关于处理行结尾的信息

Set the autocrlf to the desired value: autocrlf设置为所需的值:

How autocrlf works : autocrlf如何工作

core.autocrlf=true:    core.autocrlf=input:      core.autocrlf=false:

       repo                     repo                    repo
    /        \               /        \              /        \
crlf->lf    lf->crlf     crlf->lf       \          /            \      
 /              \        /                \      /                \

Yet another way to show how autocrlf works 另一种展示autocrlf如何工作的方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM