简体   繁体   English

MacOS VSCode git 仅在 sudo 下启动代码时有效

[英]MacOS VSCode git only works when started code under sudo

MacOS Big Sur (11.2), VSCode v1.53.1. MacOS 大苏尔 (11.2),VSCode v1.53.1。

I have X-code installed.我已经安装了 X 代码。 All these staffs started after I installed it.所有这些工作人员都是在我安装后开始的。
I did xcode-select --install and did sudo xcodebuild -license accept .我做了xcode-select --install并做了sudo xcodebuild -license accept
git was installed by brew install git . git 由brew install git

% git --version
git version 2.30.0
% where git
/usr/local/bin/git
/usr/bin/git
% which git
/usr/local/bin/git

VSCode settings.json: VSCode 设置。json:

{
    "git.path": "/usr/local/bin/git"
}

when I start code like sudo code - it works, but when I start it in normal mode I see this:当我启动像sudo code这样的代码时 - 它可以工作,但是当我在正常模式下启动它时,我看到了这个:

在此处输入图像描述

code --disable-extensions - didn't help code --disable-extensions - 没有帮助

Any git-related command from command pallet raised this error:来自命令托盘的任何与 git 相关的命令都会引发此错误:

在此处输入图像描述

When I click on "clone repository..." on Wellcome screen, I see this error:当我在 Wellcome 屏幕上单击“克隆存储库...”时,我看到此错误:

在此处输入图像描述

But, as I said, everything works fine when I start code under sudo.但是,正如我所说,当我在 sudo 下启动代码时,一切正常。

I spent days trying to solve this issue, searching a lot, but still have no clue how to solve it.我花了几天时间试图解决这个问题,搜索了很多,但仍然不知道如何解决它。 If anybody would help with that I'll be very appreciated.如果有人能提供帮助,我将不胜感激。

In my case, there was a problem in .zshenv file.就我而言, .zshenv文件存在问题。
Somehow there was line like this:不知何故有这样的线:

export TMPDIR=/tmp:$TMPDIR导出 TMPDIR=/tmp:$TMPDIR

And when some program tried to use the temp folder, this folder becomes unavailable, and the program has failed.并且当某些程序试图使用临时文件夹时,该文件夹变得不可用,并且程序已经失败。
The side effects of this stuff were also failed git and a lot of other programs.这玩意的副作用也失败了 git 和很多其他的程序。
The solution was simple: just remove this line from .zshenv解决方案很简单:只需从.zshenv中删除这一行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM