I have a small project on GitHub. The project includes a Readme.txt. Everything works fine in the repository and the newlines are still there, but when a user downloads the .zip file from the repo, the newlines disappear.
Example:
This is a line.
This is another line.This is an indented line.
This line is far below.
becomes:
This is a line.This is another line. This is an intended line.This line is far below.
This behavior makes the Readme.txt pretty hard to read, especially if it has a lot of indentation.
Is there a way to fix this? Preferably other than changing the file type.
And for clarification, I'm aiming to do this without Git, with the "Download ZIP" button in the GitHub page.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With