Git replacing LF with CRLF

1.3K    Asked by CelinaLagunas in Devops , Asked on Jun 27, 2021

Running git on a Windows XP machine, using bash. I exported my project from SVN and then cloned a bare repository.

I then pasted the export into the bare repositories directory, and did a:

git add -A

I then got a list of messages saying:

LF will be replaced by CRLF

What are the ramifications of this conversion? This is a .NET solution in Visual Studio.

Answered by Ayushi Khatri

First question arrives, Why does this warning message occur in the first place?

It can be due to Incorrect default value of core.autocrlf on Windows.

  • Now let us discuss the meaning of two types of warning messages,
  • First warning message is 'LF will be replaced by CRLF', this warning message says that you will lose your unix-style LF (Having autocrlf=true) after the commit-checkout cycle and it will be replaced by windows-style CRLF. Note that Git doesn't expect you to use unix-style LF under windows.
  • Second warning message is 'CRLF will be replaced by LF', this warning message says that you will lose your windows-style CRLF (having autocrlf=input) after performing a commit-checkout cycle and it will be replaced by unix-style LF. Note that you should not use input under windows.

Now let us see how can we resolve this issue:

During the installation process of Git itself the default value for core.autocrlf is selected.

Which is stored in system-wide gitconfig (%ProgramFiles(x86)%gitetcgitconfig).

  • Also there:
  •    'global' (per-user) gitconfig located at ~/.gitconfig, yet another
  •    'global' (per-user) gitconfig at $XDG_CONFIG_HOME/git/config or $HOME/.config/git/config and
  •    'local' (per-repo) gitconfig at .git/config in the working dir.

All you want to do is write git config core.autocrlf in the working dir to check the currently used value.

  •    add autocrlf=false to system-wide gitconfig
  •    git config --global core.autocrlf false
  •    git config --local core.autocrlf false

So for Windows:

    Keep the core.autocrlf = true if you plan to use this project under Unix as well (and unwilling to configure your editor/IDE to use unix line endings),

    Keep the core.autocrlf = false if you plan to use this project under Windows only (or you have configured your editor/IDE to use Windows line endings),

    But *remember* keep the core.autocrlf = input only you have a good reason to (eg if you're using unix utilities under windows or if you run into makefiles issues)



Your Answer

Interviews

Parent Categories