git config core.filemode false
git config --global core.filemode false
git config --global core.autocrlf false
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
git config --unset core.filemode
像魔法一样奏效,恢复了仓库的实际状态。 - LukeSavefrogs我必须执行上述filemode
和autocrlf
选项,以及
git config core.whitespace cr-at-eol
我使用的是安装了Linux子系统(WSL)的Windows系统,查看主要使用Linux构建的代码库。
我还必须为安装在Linux子系统中的Git和Windows版本的Git执行这些选项,因为VSCode使用其中一个,但我实际输入到Linux Bash中的Git命令使用另一个。
如果您使用的是cygwin并且遇到了此问题,我已经学到了一个解决方案,它不需要更改您的git设置。首先,请注意这是一个已知问题,但不打算修复。 经过大量的研究,我找到了这个gist: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
我现在将解释如何使用这些脚本的步骤:
Copy and paste the scripts to your local file system.
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%
Run chmod +x <filename>
on each file. If you forget this step, you'll get a vague error about the command not being found.
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"
Restart visual studio code.
在执行了这些步骤后,只有修改过的文件在VS Code中显示为已修改。
git add -A -- C:\project\hxcalc\package.json
和 git reset -q HEAD -- C:\project\hxcalc\package.json
都导致了 fatal: C:\project\hxcalc\package.json: 'C:\project\hxcalc\package.json' is outside repository at '/mnt/c/project/hxcalc'
。我在Cygwin bash中尝试了相同的命令,确实,Cygwin git似乎无法处理Windows路径。 - undefinedrev-parse
命令(我向原始仓库提交了一个PR)。 - undefined如果您正在使用cygwin bash,您应该知道与此相关的问题,相反,您可以使用Windows的git bash,并将其设置为vscode的默认shell。
对我来说,这些 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/docs/git-config#Documentation/git-config.txt-corefileMode
git status
告诉你什么? - rioV8git status
显示相同的文件列表并表示已修改。 - Shaggygit diff
的输出吗? - Prihexgit diff
给出了正确的输出。它只显示实际修改过的文件。 - Shaggy