Visual Studio 代码中的 Git 表示即使没有更改,文件也被修改了

问题描述 投票:0回答:8

我正在使用 Visual Studio Code 进行销售人员开发。我在使用 Git 作为存储库时遇到一些问题。当我右键单击 package.xml 并说“从 Org 检索源”时,它会从 Org 获取所有文件。

问题是 git 扩展名显示文件已在服务器上修改,即使我本地有一个示例文件。即使没有任何变化,我也不想一次又一次地将所有文件推送到我的 git 存储库。

知道为什么会发生这种情况以及如何避免它吗?

更新:我做了 git diff 并且它提供了正确的输出。它仅显示已修改的文件更改。在这种情况下只有五个。

git visual-studio-code salesforce
8个回答
52
投票

如果我们更改权限,那么我也遇到了这种行为。为了克服这个问题,您可以使用以下命令。

git config core.filemode false  

如果您想申请全球。

git config --global core.filemode false

另请参阅:git config core.filemode false 会产生什么后果?


32
投票

我能够通过执行以下命令来解决它

git config --global core.autocrlf false

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


7
投票

如果运行

git diff
并看到如下输出:

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

运行以下命令来修复问题。

git config --unset core.filemode

如果在 VS Code 中刷新源代码管理后这不起作用,也请运行以下命令。

git config --global core.filemode false

4
投票

我必须同时执行上面的

filemode
autocrlf
选项,再加上,

git config core.whitespace cr-at-eol

我在带有 Linux 子系统 (wsl) 的 Windows 系统上,正在查看主要使用 Linux 制作的代码库。

我还必须对 Linux 子系统中安装的 git 执行这些选项,然后再对 Windows 版本的 git 执行这些选项,因为 VSCode 使用了一个,但我实际的 git 命令是在 linux bash 中输入的。


2
投票

对我来说,这些 e 命令已经解决了问题:

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%20编程

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


1
投票

如果您正在使用 cygwin 并遇到此问题,我了解到了一种不需要更改 git 设置的解决方案。 首先,请注意这是一个已知问题,但不打算修复。经过大量研究,我发现了这个要点:https://gist.github.com/nickbudi/4b489f50086db805ea0f3864aa93a9f8它包括两个文件。

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

我现在将解释使用这些脚本的步骤:

  1. 将脚本复制并粘贴到本地文件系统。

  2. 在 cygpath-git-vscode.bat 中,将

    set PATH=C:\cygwin\bin;%PATH%
    更改为系统上的正确路径。对我来说,这意味着将其设置为
    set PATH=C:\cygwin64\bin;%PATH%

  3. 对每个文件运行

    chmod +x <filename>
    。如果您忘记了这一步,您将收到有关未找到命令的模糊错误。

  4. 编辑您的 Visual Studio 代码 settings.json 并将

    git.path
    设置为 cygpath-git-vscode.bat 的 Windows 路径。例如,

    "git.path": "C:\\cygwin64\\home\\user\\cygpath-git\\cygpath-git-vscode.bat"
    
  5. 重新启动 Visual Studio Code。

完成这些步骤后,只有修改过的文件在 VS Code 中显示为已修改。


1
投票

如果您使用 cygwin bash,您应该知道存在与此相关的问题,相反,您可以使用适用于 Windows 的 git bash 并将其设置为 vscode 中的默认 shell。


0
投票

只需重新启动你的 vs code 并检查对我是否有效

© www.soinside.com 2019 - 2024. All rights reserved.