[FIXED]
Hi everyone, i fixed it using agent in Cursor, he wrote this instructions for you:
I was struggling with the exact same issue in my Unity project on Windows. Every time I launched Cursor, it would touch several specific files (like Player.cs and Vehicle.cs), completely rewriting them in the Git diff even though I didn’t actually make any changes. I was forced to discard these phantom changes every single time.
I asked Cursor’s AI Agent for help, and it successfully identified the root cause and implemented a permanent fix.
The Root Cause
This is a classic line-ending conflict between CRLF (Windows) and LF (Unix/Mac). When Cursor starts up, its background processes (like language servers or formatters) index previously opened files. Because Cursor is based on VS Code and often defaults to LF, it “corrects” the line endings of files that were originally saved with CRLF. Git sees this invisible formatting change and marks the entire file as modified (red/green diff with the exact same code).
The Permanent Fix
You need to explicitly force both your editor and Git to agree on a single line-ending standard (usually LF). You can do this by adding two configuration files to the root of your project:
Step 1: Create an .editorconfig file Create a file named .editorconfig in your project root to force Cursor (and any other IDE) to always use LF.
# Tell editors how to format files
root = true
# Apply to all files
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# Exceptions for specific files (like Unity metadata)
[*.{mat,meta,prefab,unity,asset}]
charset = unset
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
Step 2: Update your .gitattributes file Create or edit .gitattributes in your project root to tell Git how to handle line endings so it stops complaining about CRLF vs LF.
# Auto-detect text files
* text=auto
# Force LF for scripts and text files
*.cs text eol=lf
*.md text eol=lf
*.json text eol=lf
*.txt text eol=lf
*.xml text eol=lf
# Keep specific files as they are (usually LF)
*.meta text eol=lf
*.unity text eol=lf
*.prefab text eol=lf
*.asset text eol=lf
What to do next:
After adding these two files, check your Git client (like GitHub Desktop). You will likely see a warning like: “This diff contains a change in line endings from ‘CRLF’ to ‘LF’”. Do NOT discard these changes. Commit the .editorconfig, .gitattributes, and the affected files.
This is a one-time process. Once committed, your files will be standardized to LF, and Cursor will never create those annoying phantom diffs on startup again. Hope this helps someone!