52

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.

Shaggy
  • 5,422
  • 28
  • 98
  • 163
  • 1
    what does command line `git status` tell you? – rioV8 Jul 04 '20 at 06:16
  • I got similar problem recently. It only happen when I delete the whole folder and replace with similar folder. Then, vscode git also show files with no changes. But when I stage all, files with no changes are no longer shown in staging area. – Pyae Jul 04 '20 at 12:30
  • Is there a specific reason that you use Visual Studio Code? If you use it just because of solving conflicts or seeing git status, I can recommend another program. – Prihex Jul 04 '20 at 17:01
  • `git status` displays the same list of files and says it is modified – Shaggy Jul 04 '20 at 21:40
  • Maybe VS Code reformat your files, can you share output of ```git diff``` – Prihex Jul 05 '20 at 03:35
  • `git diff` gives the correct output. It only displays files that are actually modified. – Shaggy Jul 09 '20 at 16:33
  • Does this answer your question? [VS code source control populates with all the files (code and zip files) from my User folder on Mac](https://stackoverflow.com/questions/54752138/vs-code-source-control-populates-with-all-the-files-code-and-zip-files-from-my) – Daniel Kaplan Aug 28 '21 at 08:54

7 Answers7

45

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

See also: What are the consequences of git config core.filemode false?

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
Senthuran
  • 1,583
  • 2
  • 15
  • 19
  • 5
    That works for me, but what are the consequences? Does this mean my committed .sh files won't be pulled as executable by others? – Daniel Kaplan Aug 28 '21 at 08:42
  • 6
    This happens amongst others if you switch between Linux filesystem and Windows filesystem, for instance, if you switch from using VScode in CMD to VScode using WSL. – anneb Mar 17 '22 at 21:53
  • 3
    I had this while switching between WSL and Windows. Installing Remote WSL extension solved this issue. – dinesh ygv May 06 '22 at 12:06
  • 3
    Take a look at https://stackoverflow.com/a/69341082/4996021 if you want to understand what this does. @DanielKaplan kindly asked his above question and got a thorough answer. – pwb2103 Jul 20 '22 at 00:45
  • Faced sutiation when changed permitions to a folder on macOS. Solved my issue. – MadaShindeInai Sep 30 '22 at 10:58
25

I was able to resolve it by executing the following command

git config --global core.autocrlf false

Documentation: https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#:~:text=with%20these%20issues.-,core.autocrlf,-If%20you%E2%80%99re%20programming

Shaggy
  • 5,422
  • 28
  • 98
  • 163
  • 7
    Funnily I had to set core.autocrlf to true to make my "modified" files disappear.. I'm using a git repo checked out on Windows that gets opened in a VS Code dev container running in Ubuntu. – stmax Jun 16 '22 at 12:13
4

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.

Ron Newcomb
  • 2,886
  • 21
  • 24
3

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
preritdas
  • 405
  • 1
  • 9
1

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.

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
1

If you are using cygwin bash you should know that there is issue related to this one, instead you can use git bash for windows and set it as default shell in vscode.

1

For me, these e command have fixed the issue:

git config --global core.filemode false
git config --global core.autocrlf false
git config --global core.whitespace cr-at-eol

https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#:~:text=with%20these%20issues.-,core.autocrlf,-If%20you%E2%80%99re%20programming

https://git-scm.com/docs/git-config#Documentation/git-config.txt-corefileMode

Budi Salah
  • 153
  • 2
  • 11