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?
当前回答
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
其他回答
我只需要从这个链接https://git-scm.com/download/win为windows安装git就可以了
不需要设置环境变量或路径。
背景: 我已经安装了VS Code,和github桌面,我克隆的回购使用github桌面。
当我打开repo时,使用VS Code,我看到了这个错误。
我通过为windows安装git来解决这个问题。
如果你有多个环境。你可以在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代码。
通过安装Git Lens Visual Code扩展,我在MacOS上用m1 pro处理器解决了同样的问题。启用扩展名后显示更改的文件。然后我重新加载VSCode,没有任何变化,但一旦我运行
git status
在终端中,显示所有的文件,并跟踪所有的更改。
Make sure git is enabled (File --> Preferences --> Git Enabled) as other have mentioned. Make sure Gits installed and in the PATH (with the correct location, by default: C:\Program Files\Git\cmd) - PATH on system variables btw Change default terminal, Powershell can be a bit funny, I recommend Git BASH but cmd is fine, this can be done by selecting the terminal dropdown and selecting 'set default shell' then creating a new terminal with the + button. Restarting VS Code, sometimes Reboot if that fails.
希望这对你有所帮助,最后但并非最不重要的是,它是'git'而不是'git' /'gat'。:)
推荐文章
- 如何从远程Git存储库中提取并覆盖本地存储库中的更改?
- Github:导入上游分支到fork
- Git单次修订的日志
- Git在不改变提交时间戳的情况下进行改基
- VS 2017 Git本地提交数据库。每次提交时锁定错误
- 如何在过去的一些任意提交之间注入一个提交?
- 从GitHub克隆项目后拉git子模块
- GitHub上的分叉和克隆有什么区别?
- 递归地按模式添加文件
- 我如何使用notepad++(或其他)与msysgit?
- 如何禁用预览文件与点击在vs代码?
- 如何将现有的解决方案从Visual Studio 2013添加到GitHub
- Git存储库中的悬垂提交和blob是什么?它们来自哪里?
- 我如何简单地从我最新的git提交创建一个补丁?
- Git显示“警告:永久添加到已知主机列表”