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?
当前回答
三年后,我遇到了同样的问题。在用户设置& path环境变量中设置路径没有帮助。我更新了Visual Studio Code,这就解决了问题。
其他回答
如果你有多个环境。你可以在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
在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代码。
VSCode 1.50(2020年9月)在问题85734中添加了一个有趣的替代方案:
Support multiple values for the git.path setting I use VSCode in three different places; my home computer, my work computer, and as a portable version I carry on a drive when I need to use a machine that doesn't have it. I use an extension to keep my settings synced up between editors, and the only issue I've encountered so far is that the git path doesn't match between any of them. On my home machine I have it installed to C of course, work likes to be funny and install it on A, and for the one on my drive I have a relative path set so that no matter what letter my drive gets, that VSCode can always find git. I already attempted to use an array myself just to see if it'd work: "git.path": ["C:\\Program Files\\Git\\bin\\git.exe", "A:\\Git\\bin\\git.exe", "..\\..\\Git\\bin\\git.exe"], But VSCode reads it as one entire value. What I'd like is for it to recognize it as an array and then try each path in order until it finds Git or runs out of paths.
这是通过PR 85954和提交c334da1解决的。
使用VSCode 1.60+
“git。启用”:真正的 git.path
通过安装Git Lens Visual Code扩展,我在MacOS上用m1 pro处理器解决了同样的问题。启用扩展名后显示更改的文件。然后我重新加载VSCode,没有任何变化,但一旦我运行
git status
在终端中,显示所有的文件,并跟踪所有的更改。
我编辑路径到系统环境,并添加“C:\Program Files\Git\bin”,然后重新启动Vscode。这对我很有效。我不明白为什么我正常使用它,然后我有这个问题。也许在安装某个东西的过程中会引起这个问题。
推荐文章
- 打开同一目录两次
- 如何从终端/命令行调用VS代码编辑器
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- 如何在Visual Studio代码中重置设置?
- Git拉另一个分支