Visual Studio Code reports "It look like git is not installed on your system." when I try to switch to the git view. I know I have git installed and used by other Git clients. I guess if I reinstall Git following Visual Studio Code's instruction ("install it with Chocolatey or download it from git-scm.com"), it probably can fix the problem, but I don't want to mess up the existing Git clients on my system. Is there a reliable way to configure Visual Studio Code so it can find existing git installation?


当前回答

如果你有多个环境。你可以在Visual Studio代码工作区设置中包含Git路径。对于Windows,根据你的设置,你可以按Ctrl + P,搜索“settings”。打开设置。json(或菜单文件→首选项→设置)。导航到工作区设置。找到“Path”并在Git bin和cmd文件夹中添加路径。

环境可以有自己的路径。当我在cmd上回显我的PC %PATH%时,我发现了这一点。Git bin和cmd路径可用,但当我在我的项目中工作时,回显% path %没有Git和cmd文件夹。如上所示,添加它们就解决了这个问题。

额外的注释:

在cmd上,你可以回显“%PATH%”,看看git bin和cmd文件夹是否包括在内。如果没有,您可以使用SETX PATH连接,例如,

SETX PATH "%PATH%;Path_to_Git_bin;Path_to_Gt_cmd;"

这将使git在本地根目录下可用,但在一些有自己路径的环境中不可用(SETX /M PATH "%PATH%;Path_to_Git_bin;Path_to_Gt_cmd;"会有)。

如果你有一个很长的路径,由于路径长度而被切断(得到“错误:截断X字符”消息),你可以在RegEdit中增加路径长度。

在“搜索窗口”中搜索“regedit”。右键单击以Administrator打开。 打开“Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem” 右键单击并修改。将值数据从0更改为1

这将增加路径长度。如果它已经是一个,那么我不确定如何从那里进行:)。

[9

其他回答

在将macOS升级到Monterey后,我遇到了这个问题。

原来xcode已经在我的mac的新更新中被删除了。只是尝试了以下建议的解决方案:

https://stackoverflow.com/a/52522566/11207358

我最近开始使用Visual Studio Code。我有这个问题,只是写Git可执行文件的确切路径解决 这个问题。代码如下:

“git。C:\Program Files\Git\bin\ Git .exe

在将macOS更新到Ventura后,我也遇到了同样的问题!

我使用下面的命令,它为我工作!

git --version

确认你是否已经安装了git,如果没有运行

brew install git

安装最新版本。

安装成功后,运行

brew link git

如果它不能符号链接,因为目标已经存在,你可以运行

brew link --overwrite git

覆盖它。

希望这对你有用!

在更新macOS后遇到了这个问题!

再次使用自制软件安装git,它工作了!

brew install git

首先在桌面上安装Git,然后在Visual Studio Code中添加包围的扩展,如图所示。

帮我解决了和你一样的问题。