步骤 6:使用 GitStep 6: Work with Git
01/28/2019
本文内容
Visual Studio 提供与本地 Git 存储库以及 GitHub 和 Azure Repos 等服务上的远程存储库的直接集成。Visual Studio provides direct integration with local Git repositories and remote repositories on services like GitHub and Azure Repos. 集成包括克隆存储库、提交更改和管理分支。The integration includes cloning a repository, committing changes, and managing branches.
本文简要概述了如何创建现有项目的本地 Git 存储库,并介绍 Visual Studio 的一些 Git 相关功能。This article provides a basic overview of creating a local Git repository for an existing project, and familiarizing yourself with some of Visual Studio's Git-related features.
在 Visual Studio 中打开项目后,比如上一步中的项目,右键单击解决方案并选择“将解决方案添加到源代码管理” 。With a project open in Visual Studio, such as the project from the previous step, right-click the solution and select Add Solution to Source Control. Visual Studio 将创建包含项目代码的本地 Git 存储库。Visual Studio creates a local Git repository that contains your project code.
Visual Studio 检测到项目托管在 Git 存储库中时,Visual Studio 窗口右下角会显示 Git 相关控件。When Visual Studio detects that the project is managed in a Git repository Git-related controls appear along the bottom right corner of the Visual Studio window. 控件显示挂起的提交、更改、存储库名称和分支。The controls show pending commits, changes, the name of the repository, and the branch. 将鼠标悬停在控件上可查看附加信息。Hover over the controls to see additional information.
新建一个存储库或选择任意 Git 控件时,Visual Studio 会打开“团队资源管理器”窗口 。When you create a new repository or select any of the Git controls, Visual Studio opens the Team Explorer window. (可随时通过“视图” > “团队资源管理器” 菜单命令打开该窗口。)窗口带有三个主窗格,你可使用“团队资源管理器”标题上的下拉菜单进行切换 。(You can open the window at any time with the View > Team Explorer menu command.) The window has three main panes, which you switch between using the drop-down on the Team Explorer header. 在选择“推送” 控件(向上箭头图标)时,还显示可用于发布内容的“同步” 窗格:The Sync pane, which provides publishing operations, also appears when you select the Push control (the up arrow icon):
选择“更改”(或带铅笔图标的 Git 控件),以查看未提交的更改并在必要时进行提交 。Select Changes (or the Git control with the pencil icon) to review uncommitted changes and to commit them when desired.
双击“更改”列表中的文件打开该文件的差异视图 :Double-click a file in the Changes list to open a diff view for that file:
选择“分支”(或带分支名称的 Git 控件),以检查分支并执行合并和变基操作 :Select Branches (or the Git control with a branch name) to examine branches and perform merge and rebase operations:
选择带存储库名称的 Git 控件(上图中的“CosineWave” )之后,“团队资源管理器” 将显示可用于迅速彻底切换到其他存储库的“连接” 接口。Selecting the Git control with the repository name (CosineWave in a previous image), Team Explorer shows a Connect interface with which you can quickly switch to another repository entirely.
使用本地存储库时,提交的更改直接进入存储库。When using a local repository, committed changes go directly into the repository. 如果已连接到远程存储库,则选择“团队资源管理器” 中的下拉列表标题,再选择“同步” 以切换到“同步” 部分,然后处理此处显示的拉取 和提取 命令。If you're connected to a remote repository, select the drop-down header in Team Explorer, choose Sync to switch to the Synchronization section, and work with the Pull and Fetch commands presented there.
深入了解Go deeper
For a short walkthrough of creating a project from a remote Git repository, see Quickstart: Clone a repository of Python code in Visual Studio.
有关更全面的教程(包括处理合并冲突、使用拉取请求查看代码、变基和挑拣分支之间的更改),请参阅开始使用 Git 和 Azure Repos。For a much more comprehensive tutorial, including handling merge conflicts, reviewing code with pull requests, rebasing, and cherry-picking changes between branches, see Get started with Git and Azure Repos.
教程回顾Tutorial review
恭喜你完成有关 Visual Studio 中 Python 的这一教程。Congratulations on completing this tutorial on Python in Visual Studio. 在本教程中,已了解如何:In this tutorial you've learned how to:
创建项目和查看项目内容。Create projects and view a project's contents.
使用代码编辑器和运行项目。Use the code editor and run a project.
使用交互 窗口开发新代码,并将该代码轻松复制到编辑器中。Use the Interactive window to develop new code and easily copy that code into the editor.
在 Visual Studio 调试器中运行已完成的程序。Run a completed program in the Visual Studio debugger.
安装程序包和管理 Python 环境。Install packages and manage Python environments.
使用 Git 存储库中的代码。Work with code in a Git repository.
在此处了解概念和操作说明指南,其中包括下文:From here, explore the Concepts and How-to guides, including the following articles: