Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"warning: LF will be replaced by CRLF in myFile" when using core.autocrlf? #1242

Closed
kiewic opened this issue Jul 18, 2017 · 17 comments · Fixed by #1767
Closed

"warning: LF will be replaced by CRLF in myFile" when using core.autocrlf? #1242

kiewic opened this issue Jul 18, 2017 · 17 comments · Fixed by #1767

Comments

@kiewic
Copy link

kiewic commented Jul 18, 2017

  • [ X] I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options

git version 2.13.0.windows.1
built from commit: eba7af3dbb4c846c6303c5f64102acee696c9ab0
sizeof-long: 4
machine: x86_64
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.15063]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

Path Option: Cmd
SSH Option: OpenSSH
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: ConHost
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Disabled
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

I have core.autocrlf enabled:

c:\> git config --global core.autocrlf

true

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

CMD

Some tools create files with LF endings. And I have core.autocrlf enabled. When I add a file to a commit, I see the following warning:

warning: LF will be replaced by CRLF in my-app/tslint.json.
The file will have its original line endings in your working directory.

It is not clear where it is going to be converted to CRLF, because the core.autocrlf option is suppose to convert CRLF endings to LF when committing a file. I was wondering if it means the file will be converted right away to CRLF in my working directory (in case the first line of the warning is disconnected from the second line), but that is not the case either.

This warning is confusing, and it is specially annoying when using git gui because I need to click the Unlock Index button for every file.

  • What did you expect to occur after running these commands?

I did not expect to see this warning, specially because adding a file to a commit is supposed to do the opposite. I think it should say "CRLF will be replaced by LF"

  • What actually happened instead?

I am not sure, it seems nothing happens.

  • If the problem was occurring with a specific repository, can you provide the
    URL to that repository to help us with testing?

No specific repository.

@tboegi
Copy link

tboegi commented Jul 24, 2017

2 comments:

I did not expect to see this warning, specially because adding a file to a commit is supposed to do the opposite.
I think it should say "CRLF will be replaced by LF"
This is not the case: On commit the CRLF will be replaced by LF, at checkout the LF will be replaced by CRLF.

In your case there are no CRLF to be converted at commit time.
But:
When you remove the file, and check it out again, it will have CRLF.
And that's why you see the warning.

Comment 2:
Did you consider to set up a ".gitattributes" file ?

@dscho
Copy link
Member

dscho commented Aug 5, 2017

@kiewic you still there?

@kiewic
Copy link
Author

kiewic commented Aug 6, 2017

Hi guys, thank you for your response.

I still feel this message is confusing, the message could be extended to include a better explanation of the issue, for example: "LF will be replaced by CRLF in file.json after removing the file and checking it out again".

Also, the following line makes more difficult to understand what does the warning mean: "The file will have its original line endings in your working directory." This is true for the current file, but it is false for the situation the warning is describing.

In addition, I see two buttons on the git gui pop-up when this warnings shows up, Unlock Index and Continue. Apparently but buttons do nothing, but it always confuses me which one I should click.

giyguiwarning

Using a .gitattributes file apparently does not suppress the warnings. I do create repositories very frequently, and I rarely create a .gitattributes file, so I think it would be greater if the root issue could be addressed.

Here is the content of my .gitattributes file:

* text=auto

Should it contain something else?

Thank you.

@dscho
Copy link
Member

dscho commented Aug 8, 2017

I do create repositories very frequently, and I rarely create a .gitattributes file

As a quick workaround (because I really have no time to spare to help you, unfortunately!), you could create a $HOME/.config/git/attributes file, i.e. in your home directory's .config\git\attributes?

@kiewic
Copy link
Author

kiewic commented Aug 9, 2017

Since I am using Windows, I tried creating the file at C:\Users\username\.config\git\attributes and I verified using Process Monitor that this file is being consumed successfully by the processes git-update-index.exe, git-check-attr.exe and git-diff-files.txt. However, this file does not suppress the warnings either. Can you confirm from my previous post that the content of my .gitattributes or attributes file is correct?

I understand you guys are very busy and I appreciate all your help. I simply wanted to brought up the issue for discussion and pseudo-documentation. Now I know how to interpret these warnings, and for now I can keep pressing the Unlock Index button whenever this happens to me.

Thank you.

@tboegi
Copy link

tboegi commented Aug 11, 2017

I would suggest to take out .json files from CRLF conversion. .gitattributes looks like this:
* text=auto
*.json -text

@dscho
Copy link
Member

dscho commented Aug 22, 2017

@kiewic did that help?

@kiewic
Copy link
Author

kiewic commented Aug 24, 2017

Do you mean if *.json -text helped? It removed all the warnings and pop-ups for .json files, but not for the rest of the files. I should not do this for all the file types auto-generated with LF line endings, I think this diminishes the purpose of text=auto or core.autocrlf = true normalization. My current settings are doing what I expect, the real problem is that the pop-up dialogue boxes are noisy and warning messages are misleading. I am fine with closing this issue as a won't fix.

@whoisj
Copy link

whoisj commented Aug 25, 2017

@kiewic any chance you have core.safeclrf = true set? I believe this is the setting which tells Git that you want to be notified of every line-ending change it performs but is unsure about (usually because the file was committed to the repository with mixed line-endings).

@kiewic
Copy link
Author

kiewic commented Aug 26, 2017

Hi @whoisj, core.safecrlf works! First I tried git config core.safecrlf true and it converted the warning into a fatal error:

fatal: LF would be replaced by CRLF in foo.json

But then I tried git config core.safecrlf false and the warnings and pop-ups are gone! Thank you!

@dscho
Copy link
Member

dscho commented Sep 18, 2017

Great to see it worked out!

@dscho dscho closed this as completed Sep 18, 2017
@kiewic
Copy link
Author

kiewic commented Jul 20, 2018

Hi, I reinstalled my computer, and this configuration stopped working. I installed git version 2.18.0.windows.1, thought I have also tried git version 2.17.1.windows.1.

Doing git config core.safecrlf false does not prevent the warning: LF will be replaced by CRLF in mapbox-search-tool/package-lock.json. The file will have its original line endings in your working directory pop-up windows anymore (and this is what I want).

Doing git config core.safecrlf true stills makes the warning a fatal error.

@whoisj
Copy link

whoisj commented Jul 20, 2018

@kiewic try running git config --list --show-origin from the root of you repository, and hopefully, there's something in the output which will give you a hint as to what is happening.

@tboegi
Copy link

tboegi commented Jul 20, 2018 via email

@dscho
Copy link
Member

dscho commented Jul 25, 2018

unfortunatly this feature doesn't work in 2.18.0.windows.1 - sorry for that. A fix is already in upstream Git. It didn't make it into 2.18, so it will be part of 2.19

@tboegi can you identify the fix more specifically? I can cherry-pick stuff into Git for Windows' master, you know 😃

@tboegi
Copy link

tboegi commented Jul 26, 2018

@dscho : That would be nice:

commit 6cb0912 (junio/as/safecrlf-quiet-fix)
Author: Anthony Sottile asottile@umich.edu
Date: Mon Jun 4 13:17:42 2018 -0700

config.c: fix regression for core.safecrlf false

A regression introduced in 8462ff43 ("convert_to_git():
safe_crlf/checksafe becomes int conv_flags", 2018-01-13) back in Git
2.17 cycle caused autocrlf rewrites to produce a warning message
despite setting safecrlf=false.

Signed-off-by: Anthony Sottile <asottile@umich.edu>
Acked-By: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

dscho added a commit to git-for-windows/build-extra that referenced this issue Jul 30, 2018
When using `core.autocrlf`, the bogus "LF
will be replaced by CRLF" warning [is now
suppressed](git-for-windows/git#1242).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@kiewic
Copy link
Author

kiewic commented Nov 8, 2018

I can confirm that git config core.safecrlf false works again in 2.19.1.windows.1. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants