#I am using git and all my file changes have ^M in the end, how to get rid of it

1 messages · Page 1 of 1 (latest)

shrewd wasp
#

Thanks

boreal lark
#

those are carriage returns (see the caret notation column here https://en.wikipedia.org/wiki/ASCII#Control_code_table )

ASCII ( ASS-kee), an acronym for American Standard Code for Information Interchange, is a character encoding standard for representing a particular set of 95 (English language focused) printable and 33 control characters – a total of 128 code points. The set of available punctuation had significant impact on the syntax of computer languages a...

#

carriage returns make up newlines by default in windows, you may know it as CRLF (carriage return + line feed)
whereas in *nix, the default is LF (line feed)

#

it's not really an issue

#

you can configure the line ending in git if you want to make it consistent though
you can add this to a .gitattributes file in the project root

* eol=lf

i usually go with this for all my projects```properties

  • text=auto eol=lf
shrewd wasp
#

vscocde says its CRLF, while git says its CR(which is M?). I am super confused. How to make it pick CRLF?

#

I think with CRLF, it will not put the ^M anymore. However I already put core.autocrlf but it still does not work

boreal lark
boreal lark
#

2 separate lines have an LF anyways

#

the ^M is the part that's it's trying to make explicit

boreal lark
shrewd wasp
#

on every line the M appears

boreal lark
#

ok, then that's a normal windows file i guess, not sure why git is choosing to display that

#

is it for every file? and what client are you using?

shrewd wasp
#

git command line

#

I wouldnt mind but git says the full file changed with M line endings

#

I have like 30 lines modified of 300

#

but git displays all modified

boreal lark
#

were you previously on *nix or something?

shrewd wasp
#

could be wsl

boreal lark
#

hmm, possibly

#

so, what i think mightve happened -

  1. the file was originally commited with LF line endings, possibly from wsl
  2. the file was now opened in windows and saved as CRLF
  3. git is choosing to display the ^M to show that it's what changed, instead of having 2 identical lines
shrewd wasp
#

its painful

#

been fightimg it for weeks

boreal lark
#

you could change the line endings back to LF within your ide to remove the excess changes for now, i guess?

boreal lark
shrewd wasp
#

warning: in the working copy of 'CuRMiTaggerWork/CuRMiTWcProjLoader.cs', LF will be replaced by CRLF the next time Git touches it

so when does git touch it? in git add?

#

Please help I am going insane here

boreal lark
#

not sure about that. i would assume any git operation that involves the file would count as git "touching" it

shrewd wasp
#

the files must be CRLF as fas as I can see, since with LF its changed and with M as well. However I have a commit with M changes and I want to commit those changes without M

#

I already did git reset --soft and I am trying to get rid of M changes. When I do a new change from there, its a M change agaoin

boreal lark
#

yeah they're being turned into CRLF in your working tree

#

but the committed version is LF

shrewd wasp
#

so why do I have M

boreal lark
#

because they're currently CRLF when the existing version is LF

shrewd wasp
#

M is Cr and not CRLF

boreal lark
#

yes, because the LF is not changed and not shown

shrewd wasp
#

the exisitng version is literally crlf, in the commit its M and when I do new changes its M again

#

LF ois shown as changed

boreal lark
#

the change is "LF" -> "CRLF"
instead of showing "LF" -> "CRLF", it's showing the actual part that changed, "<empty>" -> "CR"

shrewd wasp
#

what do you mean by change?

boreal lark
#

going from LF to CRLF, every LF is turned into CRLF

shrewd wasp
#

when is turned, on commit? or on server?

boreal lark
#

it's showing the actual data difference, which is a CR being added

boreal lark
shrewd wasp
#

oh I see

#

the difference is the CR which is M

boreal lark
#

^M, to be specific

shrewd wasp
#

it contains LF all the time

boreal lark
#

caret notation is used to notate control characters

shrewd wasp
#

so I have a commit with LF and I need to turn it to CRLF

#

Tell me how to get there without breaking my keyboard

boreal lark
#

what's your current git config regarding line endings

shrewd wasp
#

core.autocrlf

boreal lark
#

that's a setting name, not the actual setting

shrewd wasp
#

C:\code\test\ag-curmit4>git config core.autocrlf
true

boreal lark
#

ok, that's turning stuff into crlf
disable it for now

shrewd wasp
#

So by disablong it, it will keep it to LF

boreal lark
#

yeah

#

then, commit or stash your actual work, so that you don't have any changes in your working tree

#

then fix the file endings (preferably in all files via config or .gitattributes) and commit that (as a chore, if you're using conventional commits)

shrewd wasp
#

I am starting from beginning once again, need to go through 70 files

boreal lark
#

just let git handle it

shrewd wasp
#

I changed file to LF and now the entire file is displayed as changed

boreal lark
#

displayed where, exactly

shrewd wasp
#

let me redo and show you step by step

#

I soft reset the commit, I have 70 changed files

#

git diff shows me ^M everywhere

#

changed to LF with vscode, now the entire files appears changed with git diff

#

so either way I am line ending hell