gitdiffgit-diffgit-difftoolsln-file

Git shows modified files with no actual differences


I'm working on a large and complex corporate project and I'm encountering an issue with Git and Visual Studio solution files (.sln). I have two .sln files that Git identifies as completely edited, but when I compare the files using WinMerge or Beyond Compare, there are no differences between the working area and the last commit. The files are identical, including EOL, white space, etc.

Here is what I've tried:

git diff <commit-sha> --ignore-space-change -- <path>

This results in no differences being found.

When I run the command without the --ignore-space-change flag:

git diff <commit-sha> -- <path>

Git shows the diff as @@ -1,20 +1,20 @@, indicating 20 rows deleted and 20 rows added, even though the content is exactly the same and the entire file is only 20 rows.

The most confusing part is that when I stash these two files, they are added to the stash area, but they still appear in the "Changes" section. Even if I restore the files using:

git restore --source=<commit-sha> <path> 

I am still seeing these files marked as modified.

I'm stuck on how to resolve this issue. Any help or insights would be greatly appreciated.

Thank you!


Solution

  • I think I found the problem!

    In our .gitattributes file, there is a line:

    *.sln text eol=crlf
    

    After commenting out this line, Git no longer sees the past differences.

    I’m not entirely sure why this happens, because the files were already in CRLF format and still are. If anyone has an explanation, I’d love to hear it.