Git - Windows和Linux的行结尾

Bas*_*saa 6 linux windows git ubuntu line-endings

我的主要操作系统是Windows 10.

我有一个在Vagrant中运行的Ubuntu 14.04盒子,我开发了我的应用程序.该框正在运行SMB,它为我提供了对Ubuntu服务器的根文件访问.

在Ubuntu服务器上,我将我的应用程序文件放在GIT仓库中,以gitlab服务器为原点.

我在我的Windows机器上运行SourceTree,通过SMB共享连接到ubuntu GIT仓库(所以我假设它使用我的Windows GIT安装).

ubuntu机器上的Git状态不会发生任何变化.

Windows和SourceTree上的Git状态表示所有文件都已更改(因为行结尾).

为了能够在Windows和Linux上使用相同的本地存储,我应该使用哪些操作系统设置?

Big*_*her 11

在Windows上:

$ git config --global core.autocrlf true
Run Code Online (Sandbox Code Playgroud)

在Linux上:

$ git config --global core.autocrlf input
Run Code Online (Sandbox Code Playgroud)

阅读更多关于处理行结尾的信息

  • 这给出了相同的结果...... linux 上的 git status 给出了空结果,windows 上的 git status 将所有文件显示为已修改。 (2认同)
  • `$ git config --global core.autocrlf input` 在 Windows 上对我来说也足够了。 (2认同)

Cod*_*ard 9

设置autocrlf为所需的值:

如何autocrlf工作:

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

       repo                     repo                    repo
    /        \               /        \              /        \
crlf->lf    lf->crlf     crlf->lf       \          /            \      
 /              \        /                \      /                \
Run Code Online (Sandbox Code Playgroud)

另一种展示如何autocrlf运作的方式

1) true:             x -> LF -> CRLF
2) input:            x -> LF -> LF
3) false:            x -> x -> x
Run Code Online (Sandbox Code Playgroud)