Visual Studio代码无法检测已安装的git

zho*_*uji 88 git visual-studio-code

Visual Studio代码报告"看起来您的系统上没有安装git." 当我尝试切换到git视图.我知道我安装了git并被其他git客户端使用.我想如果我按照Visual Studio Code的说明重新安装git("用Chocolatey安装它或从git-scm.com下载它"),它可能可以解决问题,但我不想搞砸现有的git我系统上的客户.是否有可靠的方法来配置Visual Studio代码,以便它可以找到现有的git安装?

Nik*_*pić 110

现在,您可以配置Visual Studio代码(版本0.10.2,检查旧版本)以使用现有的git安装.

只需在Visual Studio代码设置(文件 - >首选项 - >设置)中添加git可执行文件的路径,如下所示:

{
    // Is git enabled
    "git.enabled": true,

    // Path to the git executable
    "git.path": "C:\\path\\to\\git.exe"

    // other settings
}
Run Code Online (Sandbox Code Playgroud)

  • 请注意,您必须重新启动vscode才能使更改生效. (7认同)
  • 确保安装了一个可以理解Windows路径的git版本.例如,来自MSYS2的pacman repo的那个不起作用. (2认同)
  • 像我这样的新手,你的设置在这里:文件 -> 首选项 -> 设置 (2认同)
  • 这应该设置为接受的答案 (2认同)

Edw*_*son 54

Visual Studio Code只是为您PATH寻找git.为简单起见,许多UI客户端都附带了"Portable Git",并且不添加git到路径中.

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

  • 如果你将visual studio代码中的用户设置中的git-path从`null`更新为`"F:\\ Program Files \\ Git \\ mingw64 \\ libexec \\ git-core \\ git.exe"`(您应该只需重新启动VSCode并成功打开git.我唯一的补充是,如果你不使用目录`mingw64\libexec\git-core\git.exe`中的git.exe,VSCode会打开各种错误和bash终端. (15认同)
  • @Eric,但好吧,git.path 完成了这项工作: "git.path":"d:\\Program Files\\Git\\bin\\git.exe" ;-) (4认同)
  • 这对我有用,虽然我不得不重新启动我的机器(Windows 10),但我认为我不需要。无论如何,不​​管怎样都行。 (3认同)

EdS*_*dSF 23

老帖子,但只是点击这个MAC/OSX希望这有助于某人.

症状:

  • 你已经使用VS Code了一段时间,没有任何问题Git
  • 你安装 XCode
  • 安装后XCode,VS Code突然"找不到Git并要求您在设置中安装或设置路径"

快速解决:

运行XCode(安装后第一次)并同意许可.而已.

我怎么偶然发现了这个"修复":

经过无数次的提示去有关检查后git,如which gitgit --version,后者实际上提供的这种终端消息的线索:

同意Xcode/iOS许可证需要管理员权限,请运行"sudo xcodebuild -license"然后重试此命令.

至于为什么会把XCode它包起来git,WAT

节日快乐,快乐编码:)

  • 这个解决方案对我不起作用,但运行以下命令确实有效: `xcode-select --install` [[source](https://ma.ttias.be/mac-os-xcrun-error-invalid-active-developer -路径缺失-xcrun/)] (5认同)
  • 再次更新到 Catalina 后...:| (4认同)
  • 当我升级到蒙特利时,我也偶然发现了这一点。我必须执行“xcode-select --install”,然后执行“brew update”。 (4认同)
  • 对于 BigSur 11.2,运行 `xcode-select --install` 不起作用。每次 MacOS 更新时,我发现无论 Xcode 是否是最新的,我都需要重新安装命令行工具。从 Apple 下载 – https://developer.apple.com/download/more/?=xcode (2认同)

小智 22

在Visual Studio代码中打开"用户设置":ctrl + p然后键入>settpressenter

这将打开左侧的默认设置和右侧的用户设置.

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

"git.path": "C:\\Users\\[WINDOWS_USER]\\AppData\\Local\\Programs\\Git\\bin\\git.exe"
Run Code Online (Sandbox Code Playgroud)

用您的用户名替换[WINDOWS_USER].

重新启动Visual Studio代码


Jus*_*tin 22

升级macOS后可能会发生这种情况.尝试从终端运行git,看看错误消息是否以下面的内容开头:

xcrun:错误:无效的活动开发人员路径(/ Library/Developer/CommandLineTools)...

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

xcode-select --install

从终端.有关详细信息,请参阅此答案


Rak*_*Roy 12

首先检查您的系统中是否安装了 Git*

通过在 cmd /command prompt 中键入命令(在 Windows 中)

where git
Run Code Online (Sandbox Code Playgroud)

如果你得到这样的输出

? where git
C:\cmder\vendor\git-for-windows\cmd\git.exe
Run Code Online (Sandbox Code Playgroud)

然后去Settings > Preferences > Settings把下面的代码**放在右边。

 {
    // If git enabled ?
    "git.enabled": true,

    // Path to the git executable
    "git.path": "C:\\cmder\\vendor\\git-for-windows\\cmd\\git.exe"
}
Run Code Online (Sandbox Code Playgroud)

** 就像\\上面的代码一样添加双斜线 ( ) 。

  • 文件 > 首选项 > 设置 > 用户设置 > 扩展 > Git > 路径 > 在 settings.json 中编辑(_如果显示的路径不正确_) (2认同)

sta*_*ool 11

升级到 macOS Catalina 后我遇到了这个问题。

问题解决如下:

1. 从终端找到git位置:

which git
Run Code Online (Sandbox Code Playgroud)

2. 在设置文件中将 git 的位置添加到您的位置:

设置.json

"git.path": "/usr/local/bin/git",
Run Code Online (Sandbox Code Playgroud)

根据您的平台,用户设置文件 (settings.json) 位于此处:

视窗 %APPDATA%\Code\User\settings.json

苹果系统 $HOME/Library/Application Support/Code/User/settings.json

Linux $HOME/.config/Code/User/settings.json

  • 当我将 macOS 更新到 Ventura 13 时,发生了同样的错误。这个解决方案解决了我的问题。 (5认同)

Jes*_*per 11

升级macOS\xc2\xa0v13 (Ventura) < 13.0

\n

截至 2022 年 11 月

\n

升级到 macOS\xc2\xa0v13 (Ventura) 似乎不会对您的编码环境产生太大影响。

\n

升级到 macOS\xc2\xa0v13 后,您的终端和 Visual Studio Code 将发出一些错误。例如:

\n
It looks like Git is not installed on your system ..\n
Run Code Online (Sandbox Code Playgroud)\n

或者

\n
can\'t find Git and asks you to either install or set the Path in settings\n
Run Code Online (Sandbox Code Playgroud)\n

某些错误取决于您的Z shell ( zsh) 设置或其他自定义设置。

\n

这些常见问题只需重新安装Xcode命令行工具并更新Homebrew即可解决- 由于您的终端可能会受到影响,请从 Apple 的可执行文件https://developer.apple.com/download/all/重新安装\n开发者.苹果.com。您需要使用您的 Apple ID 登录。

\n

安装后,更新 Homebrew:

\n
brew upgrade\n
Run Code Online (Sandbox Code Playgroud)\n

Mac M1 - M2机器可能有一些本机和 ARM 应用程序,因此运行:

\n
arch -arm64 brew upgrade\n
Run Code Online (Sandbox Code Playgroud)\n

关闭所有终端和 Visual Studio Code 重新启动!

\n

重新打开 Visual Studio Code,错误应该就会消失。

\n

如果 Visual Studio Code 仍在寻找 Git 路径,则需要手动添加。

\n

找到 Git 位置并从终端复制:

\n
which git\n
Run Code Online (Sandbox Code Playgroud)\n

并在 Visual Studio Code JSON 设置文件中添加 Git 可执行文件的路径(菜单File \xe2\x86\x92 Preferences \xe2\x86\x92 Settings)查找并更新该行。它应该类似于:

\n
"git.path": "/usr/local/bin/git",\n
Run Code Online (Sandbox Code Playgroud)\n


utk*_*tel 10

macOS - Visual Studio 代码。

\n

步骤 1:转到 Visual Studio Code,菜单File \xe2\x86\x92 Preferences \xe2\x86\x92 Settings(或Ctrl+ ,)。

\n

步骤 2:在搜索栏中输入“路径”。您将获得包含Git 的结果列表。

\n

第三步:点击“Git”。之后,单击Edit设置 JSON 文件中的 。

\n

步骤 4:在Mac 终端中,输入which git。您将获得 Git 路径

\n

第 5 步:只需复制该路径并在 JSON 文件中再次添加路径键即可。

\n


小智 6

在 OSX 更新后,我必须运行xcode-select --installgitlens 才能工作


kan*_*pan 6

跑步xcode-select --install。它会提示您安装命令行开发人员工具。安装工具并重新启动 Visual Studio Code。

您将看到 Git 在 Visual Studio Code 中再次运行。


小智 5

之后遇到同样的问题!

我怎么修的?

第 1 步:转到 vscode 中的设置。

第 2 步:打开 settings.json。

第 3 步:您需要在 settings.json 中找到类似“git.path”的内容

步骤4:只需添加系统中安装git的目录路径。

例如:“git.path”:“D:/Git/bin/git.exe”

第 5 步:重启你的 vscode。

希望这可以帮助。


Ami*_*lar 5

我将 macOS 升级到macOS\xc2\xa0v12 (Monterey) 后遇到了这个问题。

\n

事实证明,Xcode在我的 Mac 的新更新中已被删除。我刚刚尝试了以下建议的解决方案:

\n

macOS 更新后 Git 无法工作(“xcrun:错误:无效的活动开发人员路径 (/Library/Developer/CommandLineTools”)

\n