如何使用 Visual Studio Code 连接到我现有的 Git 存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33263491/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:38:59  来源:igfitidea点击:

How do I connect to my existing Git repository using Visual Studio Code?

gitgithubvisual-studio-code

提问by Charles L.

I've been using Visual Studio code for a long time, since v0.9.1. I now have run into the need to use GitHub and an online Git repository.

自 v0.9.1 以来,我一直在使用 Visual Studio 代码。我现在遇到了使用 GitHub 和在线 Git 存储库的需要。

I have the online Git repository set up and have been pushing changing to the online repository using GitHub. I have recently come to realize I can save myself a step with using Visual Studio Code to do both: to edit my code, then send it up to the online repository.

我已经设置了在线 Git 存储库,并且一直在使用 GitHub 推动更改到在线存储库。我最近意识到我可以使用 Visual Studio Code 为自己节省一个步骤:编辑我的代码,然后将其发送到在线存储库。

I am very new to the whole Git concept. Visual Studio Code had me install the "Git" plugin which installed Git Bash, Git CMD, and Git GUI.

我对整个 Git 概念很陌生。Visual Studio Code 让我安装了“Git”插件,该插件安装了 Git Bash、Git CMD 和 Git GUI。

This is the online repository URL I'm trying to get to: https://github.com/SpectrumGraphics/Spectrum-Graphic-Designs.git

这是我试图访问的在线存储库 URL:https: //github.com/SpectrumGraphics/Spectrum-Graphic-Designs.git

Visual Studio Code GitPlugin Visual Studio had my install

Visual Studio 代码 Git插件 Visual Studio 有我的安装

回答by Shahdat

  1. Open Visual Studio Code terminal(Ctrl+ `)
  2. Write the Git clone command. For example,

    git clone https://github.com/angular/angular-phonecat.git
    
  3. Open the folder you have just cloned (menu FileOpen Folder)

    Enter image description here

  1. 打开 Visual Studio Code终端( Ctrl+ `)
  2. 编写 Git 克隆命令。例如,

    git clone https://github.com/angular/angular-phonecat.git
    
  3. 打开刚刚克隆的文件夹(菜单FileOpen Folder

    在此处输入图片说明

回答by James Skemp

Another option is to use the built-in Command Palette, which will walk you right through cloning a Git repository to a new directory.

另一种选择是使用内置的命令面板,它将引导您将 Git 存储库克隆到新目录。

From Using Version Control in VS Code:

在 VS Code 中使用版本控制

You can clone a Git repository with the Git: Clone command in the Command Palette (Windows/Linux: Ctrl+ Shift+ P, Mac: Command+ Shift+ P). You will be asked for the URL of the remote repository and the parent directory under which to put the local repository.

您可以使用命令面板中的 Git: Clone 命令克隆 Git 存储库(Windows/Linux:Ctrl+ Shift+ P,Mac:Command+ Shift+ P)。系统将要求您提供远程存储库的 URL 和放置本地存储库的父目录。

At the bottom of Visual Studio Code you'll get status updates to the cloning. Once that's complete an information message will display near the top, allowing you to open the folder that was created.

在 Visual Studio Code 的底部,您将获得克隆的状态更新。完成后,顶部附近将显示一条信息消息,允许您打开创建的文件夹。

Note that Visual Studio Code uses your machine's Git installation, and requires 2.0.0 or higher.

请注意,Visual Studio Code 使用您机器的Git 安装,并且需要 2.0.0 或更高版本。

回答by Gishu

  1. Use git cloneto clone your repository into a folder (say work). You should see a new subfolder, work/.git.
  2. Open folder workin Visual Studio Code - everything should work fine!
  1. 用于git clone将您的存储库克隆到一个文件夹中(比如work)。您应该会看到一个新的子文件夹work/.git.
  2. 在 Visual Studio Code 中打开文件夹工作- 一切正常!

PS: Blow away the temporary folder.

PS:吹掉临时文件夹。

回答by Vamsi Ravi

Use the Git GUI in the Git plugin.

在 Git 插件中使用 Git GUI。

Clone your online repositorywith the URL which you have.

使用您拥有的 URL克隆您的在线存储库

After cloning, make changes to the files. When you make changes, you can see the number changes. Committhose changes.

克隆后,对文件进行更改。进行更改时,您可以看到数字更改。提交这些更改。

Fetchfrom the remote(to check if anything is updated while you are working).

远程获取(检查在您工作时是否有任何更新)。

If the fetchoperation gives you an update about the changes in the remote repository, make a pulloperation which will update your copy in Visual Studio Code. Otherwise, do not make a pulloperation if there aren't any changes in the remote repository.

如果fetch操作为您提供有关远程存储库中更改的更新,请执行 pull操作,这将更新您在 Visual Studio Code 中的副本。否则,如果远程存储库中没有任何更改,请不要进行拉取操作。

Push your changes to the upstream remote repository by making a push operation.

通过执行推送操作将更改推送到上游远程存储库。