Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 904
Shaggy Avatar asked Jul 04 '20 02:07

Shaggy


4 Answers

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
like image 163
Senthuran Avatar answered Oct 02 '22 07:10

Senthuran


I was able to resolve it by executing the following command

git config --global core.autocrlf false
like image 32
Shaggy Avatar answered Oct 02 '22 06:10

Shaggy


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
like image 2
preritdas Avatar answered Oct 02 '22 07:10

preritdas


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.

like image 1
Daniel Kaplan Avatar answered Oct 02 '22 07:10

Daniel Kaplan