Downloading .zip from GitHub removes newlines from text files

I have a small project on GitHub. The project includes Readme.txt. Everything works fine in the repository, and new lines still exist, but when the user loads the ZIP file from the repo, the new lines disappear.

Example:

This is a string.
This is another line.
This is an indented line.

This line is much lower.

becomes:

This is a string. This is another line. This is the intended line. the line is much lower.

This behavior makes reading Readme.txt difficult, especially if it has a lot of indentation.

Is there any way to fix this? Preferably, in addition to changing the file type.

And for clarification, I'm going to do it without Git, with the “Download ZIP” button on the GitHub page.

+6
source share
4 answers

As the nulltoken is explained , this is because GitHub runs git archive on a Linux machine, which will by default set linux line endings. You can change this by explicitly setting line endings for your repo files. To do this, create a .gitattributes file with the following contents in the root of your repo and execute it.

 *.txt eol=crlf 

All updates created by GitHub containing this file will now have CRLF line endings in all .txt files. You can expand this to all files using * instead of *.txt , but I would recommend this because it will make Linux users worse.

+8
source

Inside, the "Download Zip" function from GitHub uses the git archive .

git archive actually performs a sharp commit check, streaming content to a tar or zip archiver.

How the lines are processed during the verification process ultimately depends on the platform on which the command is executed.

Since GitHub servers are Linux-based, the selected line ending for text files will be native Linux (i.e. LF).

So there is (currently) no way to prevent this, and the text files inside your zip / tar downloads will be completed by LF.

However you can still

  • Use a tool like Unix2Dos to convert text files
  • Send an email to support@github.com and ask to change its interface so that you can select the expected line endings.
+1
source

If zip download does not work for you, the standard git method should use git archive

 git archive --format zip HEAD ..\repo.zip 

This creates a zipped version of the last tracked, committed files in the working tree in the repo.zip file. You have to execute it in your local repo.

0
source

Perhaps a better option than eol=crlf , which always converts LF to CRLF, is to use -text , which never converts anyway.

 *.patch -text 

(I have not tested this yet.)

0
source

Source: https://habr.com/ru/post/948241/


All Articles