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 Code终端来运行Git命令,而是从应用程序路径下的cmd终端运行Git命令。

其他回答

Visual Studio Code只是在PATH中查找git。为了简单起见,许多UI客户端附带了“可移植Git”,并且没有将Git添加到路径中。

如果您将现有的git客户端添加到您的PATH(以便它可以找到git.exe), Visual Studio Code应该启用git源代码控制管理。

在Visual Studio Code中,打开“用户设置”:Ctrl + P并输入>set。按回车。

这将在左侧打开默认设置,在右侧打开用户设置。

只需要在用户设置中添加git.exe的路径:

"git.path": "C:\\Users\\[WINDOWS_USER]\\AppData\\Local\\Programs\\Git\\bin\\git.exe"

用你的用户名替换[WINDOWS_USER]。

重新启动Visual Studio代码。

我编辑路径到系统环境,并添加“C:\Program Files\Git\bin”,然后重新启动Vscode。这对我很有效。我不明白为什么我正常使用它,然后我有这个问题。也许在安装某个东西的过程中会引起这个问题。

如果git在操作系统更新后丢失,在我的大苏尔的情况下,只是字面上:brew install git

这可能发生在升级macOS之后。试着在终端上运行Git,看看错误信息是否以:

xrun: error: invalid active developer path (/Library/ developer /CommandLineTools)…

如果是这样,修复是运行:

xcode-select——安装

在终点站。更多细节请看这个答案。