1

I've created sample laravel project using 2 different commands (on Windows 8):

composer create-project laravel/laravel l5linefeed dev-develop --prefer-dist

and

composer create-project laravel/laravel l5linefeed2 dev-develop

The question is about line separators - in 1st case files have Unix (LF) line endings but in the second case files has Windows (CRLF) line endings.

Questions:

  1. Why is that? Is it have anything in common with GIT? I would like to have in files original separators (the same as in packagist) and not modified

  2. If it has anything in common with Fit, when I run GIT command in cmd I get:

    git config --global -l
    
    user.name=xxx
    user.email=xxx@xxx
    core.autocrlf=false 
    

    so CLRF isn't set to true so why line endings are CRLF?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291

1 Answers1

2

I can confirm this is related to GIT.

You can set git config --global core.autocrlf input to convert all CRLF to LF on committing.

This means that Git will process all text files and make sure that CRLF is replaced with LF when writing that file to the object database. It will not, however, do the reverse. When you read files back out of the object database and write them into the working directory they will still have LFs to denote the end of line. This setting is generally used on Unix/Linux/OS X to prevent CRLFs from getting written into the repository. The idea being that if you pasted code from a web browser and accidentally got CRLFs into one of your files, Git would make sure they were replaced with LFs when you wrote to the object database.

There is also a per-repository setting where you can declare line endings for specific files. Therefore a .gitattributes file must be created in your repo. For some examples see https://help.github.com/articles/dealing-with-line-endings/#per-repository-settings. The advantage of the per-repository setting is that every user who pulls from your repo has the same line ending settings.

Since any good windows editor should support both CRLF and LF I see no problem with using LF only.

Difference between dist and source

Run composer show laravel/laravel and you can see

source   : [git] https://github.com/laravel/laravel.git 4afcd8c278febbe6840dbf8bbb46514818abce59
dist     : [zip] https://api.github.com/repos/laravel/laravel/zipball/4afcd8c278febbe6840dbf8bbb46514818abce59 4afcd8c278febbe6840dbf8bbb46514818abce59

The composer option --prefer-dist is a non version control zip archive. Mostly this is the faster way than source and default for stable versions.

If --prefer-source is used composer will clone from the git repository. Because you are not on a stable version source is used if you omit --prefer-dist.

Why dist is LF

The zip archive is downloaded and extracted. No git actions are performed the line feed is obtained as provided in the repo/zip.

Why source is CRLF

The git repository is cloned and checked out from github. The laravel repository has a .gitattributes file containing

* text=auto
  • Note: .gitattributes has higher priority than git config

* text=auto will make Git handle the files in whatever way it thinks is best. Now you are on Windows and Git thinks it is best to change it to CRLF as this is the default for Windows I think.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • But why line endings are CLRF when I have `core.autocrlf=false `? Shouldn't they be exact the same as in repository? And for editing files later I use PhpStorm – Marcin Nabiałek Jan 08 '15 at 12:42
  • Thanks, it's much more clear at the moment. Is there any way to force GIT on my PC to always use LF feeds instead of CRLF ? If you have a while, you could also look at http://stackoverflow.com/questions/27730350/phpstorm-git-line-endings-changing-from-lf-to-crlf – Marcin Nabiałek Jan 08 '15 at 14:15
  • yes as I wrote in my original answer use: `git config --global core.autocrlf input` – Pᴇʜ Jan 08 '15 at 14:23