Extelliqent
Extelliqent

Reputation: 1858

Visual Studio Code shows file modified when it's not

I am experiencing the same issue like here: enter image description here Git in Visual studio code says file is modified even when there is no change

Whole bunch of files shows as they are modified under source control but their contents are the same. I ran recommended 3 below no help..

git config core.filemode false  
git config --global core.filemode false
git config --global core.autocrlf false

Upvotes: 6

Views: 7177

Answers (3)

Tarek Ghali
Tarek Ghali

Reputation: 1

I just deleted and downloaded the prettier formatting, and the problems and changes in the git extension disappeared.

Upvotes: 0

Preston Software
Preston Software

Reputation: 379

You say you are using prettier to format the files: I would look there. It may trim trailing whitespace. It may add trailing newlines at the end of the file as required by git. Without a proper diff or screen shot of a diff I can only guess.

I use an .editorconfig file with entries like the one below to protect files where trailing whitespace is part of the syntax. The second entry is another example where prettier formatting may cause issues.

[*.md]
trim_trailing_whitespace = false

# The indent size used in the `package.json` file cannot be changed
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
[{*.yml,*.yaml,package.json}]
indent_style = space
indent_size = 2

I think prettier respects editorconfigs (like most tools) and vscode can be made to with a plugin. Since you are formatting many repositories at once, I am not sure which files would apply and when.

Next I would look at your vscode settings. Here is a partial settings.json which serves the same purpose as the example above. Just about each setting has an equivalent in the interface. Look up each setting or search the "command palette" to find them quickly.

// Place your settings in this file to overwrite default and user settings.
{
  "files.trimTrailingWhitespace": true,
  "files.insertFinalNewline": true,
  "[plaintext]": {
    "files.insertFinalNewline": false
  },
  "[markdown]": {
    "files.trimTrailingWhitespace": false
  }
}

These vscode settings in particular are important for me to avoid unexpected issues like the one your having.

Lastly, check your .gitattributes files in the root of each repository. They will override your global git settings on a per project basis. Important entries for me are:

# Auto detect text files and perform LF normalization
* text=auto

# Special files
LICENSE.txt eol=crlf

# Reasonable Defaults
*.bat eol=crlf
*.cmd eol=crlf
*.ps1 eol=lf
*.sh eol=lf
*.rtf -text

You may be able to side step these issues by instructing git on how you want things handled. Personally, I have similar issues with PDF files in my repos from different platforms. This creates a few problems in git itself (where files are marked modified but changes can't be discarded.)

Upvotes: 2

kingpanda419
kingpanda419

Reputation: 141

I suggest that you should better check the auto-save function for visual-studio-code

Upvotes: 1

Related Questions