如何将现有本地工作目录的 git 版本控制与 Visual Studio 代码相结合?

How to combine git version control of existing local working directories with Visual Studio Code?

直到最近,我一直在通过安装在 Cygwin 中的 git 在 Windows 机器上维护各种编码项目的版本控制。我现在正在切换到 Visual Studio 代码作为文本编辑器(我仍然计划通过命令行编译,至少现在是这样)。

为了尽量减少双重安装,我将 VS Code 的 git.path 变量设置为 Cygwin 目录中的 git 可执行文件。但是,我遇到一个问题,即 VS Code 似乎无法识别我已经存在的本地 git 工作目录,即使在根目录级别的 VS Code 中打开文件夹时也是如此(我在网上搜索过并且只提出一两年前的讨论表明这是必要的)。当我单击 SOURCE CONTROL 选项卡时,我看到 There are no active source control providers

有没有办法不必通过 VS Code 克隆 duplicate/replacement 工作目录并强制它使用已经克隆的目录?我知道我可以继续将 Cygwin 用于 git,并将 VS Code 用作文本编辑器,但我希望能够使用 VS Code 的一些有用 git 功能。

只需在任何地方使用 Git for Windows instead of Cygwin: you can unzip PortableGit-2.17.0-64-bit.7z.exe

然后 VSCode 将毫无问题地识别您现有的存储库。
将其与 GitLens 相结合,您可以直接从编辑器中完成大部分 Git 操作。


注意:如果你真的真的不得不使用 Cygwin,Microsoft/vscode issue 7998 reports (by Eric DraconPern) :

my solution was to install Git for Windows, and then use mklink to junction link the Cygwin .ssh directory to %USERNAME%/.ssh to share config and ssh key.
Then both Git will have access to the same ssh key and ssh config for multiple key usage.
Also put the Cygwin\bin path first in %PATH% environment variable.

同样的问题也提到nukata/cyg-git

This provides a Git for Windows virtually. You only need Cygwin and its packages.

I had once tried the Go plugin for VSCode on Windows 10 and found that it required Git for Windows implicitly. However, it was redundant since I had already installed Cygwin and its git package. So I wrote this proxy and wrapper.

Dmitry Katsubo proposes a bash version of that same script.


如果你使用的是Windows 10,我会推荐WSL (Windows Subsystem for Linux),在那里你可以安装Git(Linux原始版本)。