'Git in Visual studio code says file is modified even when there is no change

I am using the Visual Studio Code for my salesforce development. I have some issues with Git as a repository. When I right-click on the package.xml and say Retrieve Source From Org, it is getting all the files from Org.

The problem is git extension is showing file is modified on the server even though I have a sample file in my local. I don't want to push all the files again and again to my git repo even when there is no change.

enter image description here

Any idea why this is happening and how to avoid it?

Update: I did git diff and it provides correct output. It only shows file changes that are modified. In this case only five.



Solution 1:[1]

I was able to resolve it by executing the following command

git config --global core.autocrlf false

Solution 2:[2]

If we change the permission using then I also encountered that behavior. In order to overcome from this issue you can use the below commands.

git config core.filemode false  

In case you want to apply for the global.

git config --global core.filemode false

Solution 3:[3]

I had to do both the filemode and the autocrlf options above, plus,

git config core.whitespace cr-at-eol

I'm on a windows system with a linux subsystem (wsl), looking at a primarily made-with-linux codebase.

I also had to do those options both for the git installed in the linux subsystem and then again for the windows version of git, since VSCode used one but my actual git commands I enter into linux bash.

Solution 4:[4]

If you are using cygwin and experiencing this issue, I have learned of a solution that doesn't require changing your git settings. First, be aware that this is a known issue but it is not planned on being fixed. After a bunch of research, I found this gist: https://gist.github.com/nickbudi/4b489f50086db805ea0f3864aa93a9f8 It consists of two files.

cygpath-git-editor.sh:

#!/bin/bash

# wrapper to convert linux paths to windows
# so vscode will work as a git editor with cygwin
# editor="/home/this/file.sh" in .gitconfig

# extract last argument (the file path)
for last; do true; done

# get all the initial command arguments
all="${@:1:$(($#-1))}"

# launch editor with windows path
code $all $(cygpath -w $last) 

cygpath-git-vscode.bat:

@echo off

REM wrapper to convert linux paths to windows
REM so vscode git integration will work with cygwin
REM "git.path"="C:\\this\\file.bat" in settings.json

setlocal
set PATH=C:\cygwin\bin;%PATH%

if "%1" equ "rev-parse" goto rev_parse
git %*
goto :eof
:rev_parse
for /f %%1 in ('git %*') do cygpath -w %%1

I will now explain the steps to use these scripts:

  1. Copy and paste the scripts to your local file system.

  2. In cygpath-git-vscode.bat, change set PATH=C:\cygwin\bin;%PATH% to the correct path on your system. For me, that meant setting it to set PATH=C:\cygwin64\bin;%PATH%

  3. Run chmod +x <filename> on each file. If you forget this step, you'll get a vague error about the command not being found.

  4. Edit your visual studio code settings.json and set git.path to the windows path to cygpath-git-vscode.bat. e.g.,

    "git.path": "C:\\cygwin64\\home\\user\\cygpath-git\\cygpath-git-vscode.bat"
    
  5. Restart visual studio code.

After those steps, only the modified files showed as modified in VS Code.

Solution 5:[5]

If you run git diff and see an output such as:

diff --git a/folder/file.tex b/folder/file.tex
old mode 100725
new mode 100614

Run the following command to fix the issue.

git config --unset core.filemode

If this doesn't work after refreshing source control in VS Code, run the following command as well.

git config --global core.filemode false

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shaggy
Solution 2 Senthuran
Solution 3 Ron Newcomb
Solution 4 Daniel Kaplan
Solution 5 preritdas