Disable git EOL Conversions

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:

enter image description here

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.

enter image description here

For users of TortoiseGIT: the Auto CrLf convert settings are on the GUI, in section GIT.


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.


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 non-text when doing line-ending-normalization, disabling it completely.


One simple solution is:

  • make sure core.autocrlf is set to false for all repos:
    git config --global core.autocrlf false
    • Git 2.16 (Q1 2018) and above, run git add --renormalize .
    • otherwise, re-clone your repo, and check no EOL conversion is done.

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

Tags:

Git