'How to stop github from modifying my files (in workflow)?

On github.com, I have a little 6-byte file hello.txt consisting of "hello" and a newline:1

enter image description here

In an Ubuntu-18 workflow with runs-on: ubuntu-18.04, we have:

enter image description here

But on Windows with runs-on: windows-2019, there is miraculously an extra byte:2

enter image description here

How do I get rid of this extra byte?


Update: After studying James' quick answer, I opted for a one-line .gitattributes file in the directory where my hello.txt was located:

* -text

That directory consists of test data only.


1 I do not know why GitHub drops the .txt extension, but I am an newbie.
2 We can all assume the extra byte is a carriage-return.



Solution 1:[1]

Line ending handling can be configured in quite a few different ways.

I'm pretty sure on Windows when you install git, there's a popup where it asks you how you want to handle CRLF's, but it's been a while since I did a fresh install.

Check out the official docs here on how you can configure it: https://docs.github.com/en/github/getting-started-with-github/configuring-git-to-handle-line-endings

From the Docs on the .gitattributes options:


  • text=auto Git will handle the files in whatever way it thinks is best. This is a good default option.

  • text eol=crlf Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux.

  • text eol=lf Git will always convert line endings to LF on checkout. You should use this for files that must keep LF endings, even on Windows.

  • binary Git will understand that the files specified are not text, and it should not try to change them. The binary setting is also an alias for -text -diff.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James