Downloading a .zip from GitHub removes newlines from text files

As nulltoken explained, this is caused by the fact that GitHub runs git archive on a linux machine that will default to linux line endings. You can change this by explicitly setting line endings for the files in your repo. To achieve this, create a .gitattributes file with the following content in the root of your repo and commit it.

*.txt eol=crlf

All GitHub created zips of revisions that contain that file will now have CRLF line endings in all .txt files. You can expand that to all files by using * instead of *.txt, but I would advice against that because it will make linux users sad.


Internally, the "Download Zip" feature from GitHub leverages git archive.

git archive actually performs a checkout of the pointed at commit, streaming the content to the tar or zip archiver.

The way the line endings are being dealt with, during the checkout process, eventually depends on the platform the command is being run on.

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

So there's (currently) no way to interfere with this and text files inside your zip/tar downloads will be LF terminated.

However you may still

  • Use a tool like Unix2Dos to batch convert your text files
  • Send a mail to [email protected] and request for a change to their UI so that one could potentially select the expected line endings

Tags:

Git

Github