Why does VSCode insert carriage return marked by ^M in gitt diff?

1.2k Views Asked by At

I'm running Ubuntu on WSL2 and VSCode on top of that. Although I have the "LF" setting on VSCode, whenever I save the file, VSCode insists on inserting a carriage return that gets marked as ^M with git diff. Check it out:

diff --git a/network/outputs.tf b/network/outputs.tf
index e13366b..f7cc29c 100644
--- a/network/outputs.tf
+++ b/network/outputs.tf
@@ -1,4 +1,4 @@
-output "vpc_id" {
-    description = "The ID of the Main VPC"
-    value       = aws_vpc.main.id
+output "vpc_id" {^M
+    description = "The ID of the Main VPC"^M
+    value       = aws_vpc.main.id^M
 }

I have no problem with this on VIM.

1

There are 1 best solutions below

2
VonC On

If git config --global core.autocrlf=false is not enough, check if there is a .gitattributes rule (typically core.eol) which could influence how Git commit the file:

git check-attr --all -- network/outputs.tf