0

In this answer, I found the following chart:

How autocrlf works:

core.autocrlf=true:      core.autocrlf=input:     core.autocrlf=false:

        repo                     repo                     repo
      ^      V                 ^      V                 ^      V
     /        \               /        \               /        \
crlf->lf    lf->crl      crlf->lf       \             /          \      
   /            \           /            \           /            \

I do most of the development and unit testing locally on a windows box, but the main git repository is on a unix machine, and the code is used on multiple unix machines.

I don't really care how the line endings appear in my windows, but I want very much to not have any CRLF in the repository.

I'm using PyCharm, if that makes any difference.

Here's my git settings:

# ~/.gitconfig :
[user]
    name = ***
    email = ***
[core]
    autocrlf = true
    eol = lf

and

# <path-to-my-project>/.git/config :
[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    autocrlf = true
[remote "origin"]
    url = git+ssh://***
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

I'd think I have the correct setup, and yet I get the warning: LF will be replaced by CRLF in

My current workaround is to sftp the files to a unix box and commit/push my changes from there, which is really annoying.

How do I fix this?

Granny Aching
  • 1,295
  • 12
  • 37
  • 1
    Possible duplicate of [How to change line-ending settings](https://stackoverflow.com/questions/10418975/how-to-change-line-ending-settings) – Idemax Apr 05 '19 at 22:08

3 Answers3

0

The easiest way to do this is to use a gitattributes file and specify * text=auto. Git will then look at files, guess whether they are text or binary, and perform automatic line ending conversion for you (provided the file was committed with LF endings originally). You can do this by creating a .gitattributes file with those contents in the repository or writing a custom one in .git/info/attributes. See the gitattributes documentation for more details.

Once you've done that, you can then set core.eol in your config (but not core.autocrlf) to whatever you want to use. If you set it to crlf or native (the default), Git will check files out in CRLF, and since they're text, it will write them with LF into the repository. If you specify lf, then you'll get LF always, even in the working tree.

The alternative is to specify core.autocrlf (and not core.eol) to true, which is equivalent to setting your gitattributes to contain * text=auto and core.eol to crlf.

bk2204
  • 64,793
  • 6
  • 84
  • 100
0

.... or you could ask git to not mess with eol at all and let you handle it. In .gitattributes:

*    -text

That will do.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
0

1.Set core.autocrlf to false: Before you modify the line endings, run the following command to disable automatic line ending conversion:

git config core.autocrlf false

2.Run Line Ending Conversion: After disabling automatic line ending conversion, Run the following command to change the line endings of all tracked files in your repository from CRLF to LF:

git rm --cached -r .
git reset --hard

For above step, Backup Your Changes and ensure that you don't have any uncommitted changes that you want to keep before proceeding,.

mnnim
  • 31
  • 2