4

I used to get warnings about LF will be replaced by CRLF when doing a git commit.

I played around with autocrlf but setting it to true or false both caused problems. In the end, after this comment (LF will be replaced by CRLF in git - What is that and is it important?) by @Drew Noakes, I just unset it and that fixed the warnings.

However, now, when I run git diff I get output like this:

-       original line;
+       new line;^M

What's going on and is there any way of getting rid of these pesky ^Ms once and for all?

If it helps, this is my own repo (i.e. I have complete control over the code base) and I'm on a Mac.

2
  • Do you have .gitattributes files with core.eol directive in it?
    – VonC
    Commented Feb 20, 2015 at 9:20
  • @VonC I don't but I do have a .gitattributes file with *.pbxproj -crlf -diff -merge in it. I assume that's got nothing to do with the problem as it's only applying this to pbxproj files.
    – Snowcrash
    Commented Feb 20, 2015 at 9:24

2 Answers 2

1

Try running dos2unix or a similar program on the tex file.

2
  • Broken link. Here's a good one: dos2unix Commented Apr 6, 2020 at 19:38
  • Warning: this could change every line in your git file. Commented May 11, 2021 at 16:47
0

To remove them, you can execute something like this from your shell:

$ find -type f -exec sed -i -e 's/^M//g' {} +

... where you need to insert ^M using [Ctrl+V] [Ctrl+M] (see here for more options remove ^M characters from file using sed). Since you're on a Mac, they shouldn't come back after that, but I admit I'm not entirely sure about git not putting them back.

Not the answer you're looking for? Browse other questions tagged or ask your own question.