Visual Studio Code 无法检测到已安装的 git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29971624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Code cannot detect installed git
提问by zhouji
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 re-install 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。” 当我尝试切换到 git 视图时。我知道我已经安装了 git 并被其他 git 客户端使用。我想如果我按照 Visual Studio Code 的说明(“用 Chocolatey 安装它或从 git-scm.com 下载它”)重新安装 git,它可能可以解决问题,但我不想弄乱现有的 git我系统上的客户。有没有可靠的方法来配置 Visual Studio Code 以便它可以找到现有的 git 安装?
采纳答案by Edward Thomson
Visual Studio Code simply looks in your PATH
for git
. Many UI clients ship with a "Portable Git" for simplicity, and do not add git
to the path.
Visual Studio Code 只是在您的PATH
for 中查找git
。为简单起见,许多 UI 客户端附带了“便携式 Git”,并且不会添加git
到路径中。
If you add your existing git client to your PATH
(so that it can find git.exe
), Visual Studio Code should enable Git source control management.
如果您将现有的 git 客户端添加到您的PATH
(以便它可以找到git.exe
),Visual Studio Code 应该启用 Git 源代码控制管理。
回答by Nikola Prokopi?
Now you can configure Visual Studio Code (version 0.10.2, check for older versions) to use existing git installation.
现在您可以配置 Visual Studio Code(版本 0.10.2,检查旧版本)以使用现有的 git 安装。
Just add the path to the git executable in your Visual Studio Code settings (File -> Preferences -> Settings) like this:
只需在 Visual Studio Code 设置(文件 -> 首选项 -> 设置)中添加 git 可执行文件的路径,如下所示:
{
// Is git enabled
"git.enabled": true,
// Path to the git executable
"git.path": "C:\path\to\git.exe"
// other settings
}
回答by EdSF
Update 2020 (Mac)
2020 年更新 (Mac)
Went through this $h!?
again after updating to Catalina, which requires an XCode
update.
$h!?
更新到需要XCode
更新的Catalina 后再次经历了这个过程。
And to clarify, while this post is about VS Code
, this issue, is system wide. Your git
install is affected/hosed. You can try to run git
in your terminal/bash/zsh or whatever it is now and it just won't.
澄清一下,虽然这篇文章是关于VS Code
这个问题的,但它是系统范围的。您的git
安装受到影响/托管。您可以尝试git
在您的终端/bash/zsh 或现在的任何地方运行,但它不会。
Same fix, just update XCode
, start it up and agree to license. That's it.
同样的修复,只需更新XCode
,启动它并同意许可。就是这样。
Old post, but just hit this on MAC/OSX
so hope this helps someone.
旧帖子,但只是点击这个,MAC/OSX
所以希望这对某人有所帮助。
Symptoms:
症状:
- You've been using
VS Code
for some time and have no issues withGit
- You install
XCode
(for whatever reason- OS update, etc) - After installing
XCode
,VS Code
suddenly "can't find Git and asks you to either install or set the Path in settings"
- 您已经使用
VS Code
一段时间了,没有任何问题Git
- 您安装
XCode
(无论出于何种原因- 操作系统更新等) - 安装后
XCode
,VS Code
突然“找不到Git并要求您在设置中安装或设置路径”
Quick fix:
快速解决:
Run XCode
(for the first time, after installing) and agree to license. That's it.
运行XCode
(第一次,安装后)并同意许可。就是这样。
How I stumbled upon this "fix":
我是如何偶然发现这个“修复”的:
After going through numerous tips about checking git
, e.g. which git
and git --version
, the latter actually offered clues with this Terminal message:
在经历了许多有关检查的提示后git
,例如which git
和git --version
,后者实际上提供了带有此终端消息的线索:
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
同意 Xcode/iOS 许可证需要管理员权限,请运行“sudo xcodebuild -license”,然后重试此命令。
As to whyXCode
would even wrap it's hands on git
, WAT
至于为什么XCode
要把它的手包起来git
,WAT
Happy holidays and happy coding :)
节日快乐,编码愉快:)
回答by Bartosh
In Visual Studio Code open 'user settings': ctrl + p
and type >sett
press enter
在 Visual Studio Code 中打开“用户设置”:ctrl + p
并输入>sett
pressenter
This will open default settings on left side and User settings on right side.
这将打开左侧的默认设置和右侧的用户设置。
Just add path to git.exe in user settings
只需在用户设置中添加 git.exe 的路径
"git.path": "C:\Users\[WINDOWS_USER]\AppData\Local\Programs\Git\bin\git.exe"
Replace [WINDOWS_USER] with your user name.
将 [WINDOWS_USER] 替换为您的用户名。
Restart Visual Studio Code
重新启动 Visual Studio 代码
回答by Just Another Justin
This can happen after upgrading macOS. Try running git from a terminal and see if the error message begins with:
升级 macOS 后可能会发生这种情况。尝试从终端运行 git 并查看错误消息是否以以下开头:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) ...
xcrun: 错误: 无效的活动开发者路径 (/Library/Developer/CommandLineTools) ...
If so the fix is to run
如果是这样,修复是运行
xcode-select --install
xcode-select --install
from the terminal. see this answerfor more details
从终端。有关更多详细信息,请参阅此答案
回答by Rakesh Roy
First check if Git* installed or not in your system
首先检查您的系统中是否安装了 Git*
by typing the command in cmd /command prompt (In windows)
通过在 cmd /command prompt 中键入命令(在 Windows 中)
where git
if you get an output like this
如果你得到这样的输出
λ where git
C:\cmder\vendor\git-for-windows\cmd\git.exe
Then Go to Settings > Preferences > Settings
and put the bellow code** right part.
然后去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"
}
- If you don't have Git installed , Install git from here https://git-scm.com/
- 如果您没有安装 Git,请从这里安装 git https://git-scm.com/
** Just add double slash (\\
) just like the above code.
** 就像\\
上面的代码一样添加双斜线 ( ) 。
回答by Pengyy
I faced this problem on MacOS High Sierra 10.13.5
after upgrading Xcode
.
MacOS High Sierra 10.13.5
升级后我遇到了这个问题Xcode
。
When I run git
command, I received below message:
当我运行git
命令时,我收到以下消息:
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
同意 Xcode/iOS 许可证需要管理员权限,请运行“sudo xcodebuild -license”,然后重试此命令。
After running sudo xcodebuild -license
command, below message appears:
运行sudo xcodebuild -license
命令后,出现以下消息:
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
Hit the Enter key to view the license agreements at '/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'
您尚未同意 Xcode 许可协议。您必须同意以下两个许可协议才能使用 Xcode。
按 Enter 键查看“/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf”中的许可协议
Typing Enter
key to open license agreements and typing space
key to review details of it, until below message appears:
键入Enter
密钥以打开许可协议并键入space
密钥以查看其详细信息,直到出现以下消息:
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel]
输入“同意”即表示您同意软件许可协议的条款。输入“打印”以打印它们或输入任何其他内容以取消,[同意,打印,取消]
The final step is simply typing agree
to sign with the license agreement.
最后一步是简单地键入agree
以签署许可协议。
After typing git
command, we can check that VSCode detected git again.
输入git
命令后,我们可以检查 VSCode 是否再次检测到 git。
回答by Induja VJ
After an OSX update i had to run xcode-select --install
for the gitlens to work
在 OSX 更新后,我必须运行xcode-select --install
gitlens 才能工作
回答by stayingcool
I had this problem after upgrading to macOS Catalina.
升级到 macOS Catalina 后我遇到了这个问题。
The issue is resolved as follows:
问题解决如下:
1.Find git location from the terminal:
1.从终端找到git位置:
which git
2.Add the location of git in settings file with your location:
2.在设置文件中将 git 的位置添加到您的位置:
settings.json
设置.json
"git.path": "/usr/local/bin/git",
Depending on your platform, the user settings file (settings.json) is located here:
Windows
%APPDATA%\Code\User\settings.json
macOS
$HOME/Library/Application Support/Code/User/settings.json
Linux
$HOME/.config/Code/User/settings.json
根据您的平台,用户设置文件 (settings.json) 位于此处:
视窗
%APPDATA%\Code\User\settings.json
苹果系统
$HOME/Library/Application Support/Code/User/settings.json
Linux
$HOME/.config/Code/User/settings.json
回答by Ajmal Aamir
i have recently start visual studio code and have this issue and just write the exact path of executable git solve the issue .... here is the code ...
我最近启动了 Visual Studio 代码并遇到了这个问题,只需编写可执行 git 的确切路径即可解决问题......这里是代码......
"git.path": "C:\Program Files\Git\bin\git.exe",
"git.path": "C:\Program Files\Git\bin\git.exe",