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
其他回答
如果git在操作系统更新后丢失,在我的大苏尔的情况下,只是字面上:brew install git
首先在桌面上安装Git,然后在Visual Studio Code中添加包围的扩展,如图所示。
帮我解决了和你一样的问题。
首先检查Git*是否安装在你的系统中,在cmd /命令提示符中输入命令(在Windows中):
where git
如果你得到这样的输出,
λ where git
C:\cmder\vendor\git-for-windows\cmd\git.exe
然后进入设置→首选项→设置,把下面的代码**放在右边。
{
// If git enabled?
"git.enabled": true,
// Path to the Git executable
"git.path": "C:\\cmder\\vendor\\git-for-windows\\cmd\\git.exe"
}
如果您没有安装Git,请从https://git-scm.com/安装Git
**只需添加一个双斜杠(\\),就像上面的代码一样。
这可能发生在升级macOS之后。试着在终端上运行Git,看看错误信息是否以:
xrun: error: invalid active developer path (/Library/ developer /CommandLineTools)…
如果是这样,修复是运行:
xcode-select——安装
在终点站。更多细节请看这个答案。
Open
C:\Users\nassim\AppData\Roaming\Code\User\settings.json
注释任何Git行:
// ...
// "git-graph.integratedTerminalShell": "E:\\Apps\\Git\\bin\\bash.exe",
// "git.path": ""
//...
将“git.exe”添加到操作系统路径下。
注意:修复这个Git错误也修复了npm错误。因为它们都是在路径中定义的,如果一个失败了,其余的也会失败。
推荐文章
- 打开同一目录两次
- 如何从终端/命令行调用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拉另一个分支