简体   繁体   中英

Files when modified appear as new files git

I have a problem with git when modifying some files from the same project Appear like new For example, I have an a.php file

-
-namespace Core;
-
-interface IKernel
-{
-    public static function Start();
-}

When modifying it after adding it in git, the file appears as new. It does not show me the location of the modification

-
-namespace Core;
-
-interface IKernel
-{
-    public static function Start();
-}

//s

git diff

-<?php
-
-namespace Core;
-
-interface IKernel
-{
-    public static function Start();
-}
+<?php^M
+^M
+namespace Core;^M
+^M
+interface IKernel^M
+{^M
+    public static function Start();^M
+}^M
+^M
+//s

https://github.com/i74ifa/UnknownRori-PHP/commit/1459d6903c4dccf09b6992b4fe8621cd13a31a83?diff=split

Take a look at this commit for clarity

I added line 7 and it thinks I made a new file

hope it's clear

It sounds like what you're seeing is git diff reporting all lines as modified instead of just the one you added.

If you run git diff -w (--ignore-all-space ) you should see just the new line.

This happens when your text editor saved the file with different line endings than it had originally. That's why all lines appear as modified.

If you didn't convert the line endings yourself by accident, you should configure your editor to keep the original line endings when saving a file. If you're working on a team, Editorconfig is a good way to ensure that everyone's editors is configured to use the same line endings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM