You can set the mode to use by adding an additional parameter of true or false to the above command line. If core. autocrlf is set to true, that means that any time you add a file to the Git repository that Git thinks is a text file, it will turn all CRLF line endings to just LF before it stores it in the commit.
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.
Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character. The history of these two control characters dates back to the era of the typewriter.
Inside your project, there should be a .gitattributes
file. Most of the time, it should look like below (or this screen-shot):
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
# Never modify line endings of our bash scripts
*.sh -crlf
#
# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
*.css text
*.html text
*.java text
*.js text
*.json text
*.properties text
*.txt text
*.xml text
# These files are binary and should be left untouched
# (binary is macro for -text -diff)
*.class binary
*.jar binary
*.gif binary
*.jpg binary
*.png binary
Change * text=auto
to * text=false
to disable automatic handling (see screen-shot).
Like this:
If your project doesn't have a .gitattributes file, then the line endings are set by your git configurations. To change your git configurations, do this:
Go to the config file in this directory:
1) C:\ProgramData\Git\config
2) Open up the config file in Notepad++ (or whatever text editor you prefer)
3) Change "autocrlf=" to false.
One simple solution is:
git config --global core.autocrlf false
git add --renormalize .
If there are conversions automatically done, that mean a .gitattributes
core.eol
directive is there within the repo.
With Git 2.8+ (March 2016), check if there are still eol transformation with:
git ls-files --eol
Here is how you do this for a single repo.
Create the file .gitattributes
at the root of the repo with this line in it
* -text
That's it. This is a wildcard matching all files, telling git to unset the text attribute. This means git treats all files as binary, and thus does not perform any line-ending conversion.
I figured it out. It seems that the SCP program was converting the line endings. I noticed this when I tried deliberately making a file with LF endings and then observing that it appeared as CRLF when downloaded.
Since this was the solution for me, I'm accepting this answer, but people of the future should also refer to the other answers for a more general solution.
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