git Visual Studio 2015 如何将分支合并到 master 中?

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

Visual Studio 2015 How to merge a branch into master?

gitvisual-studioversion-controlgit-branchgit-merge

提问by Lord of Scripts

I am new to GIT, so far I had been using Visual Studio Online TFS for my version control and I am the onlydeveloper. When I created my last project I was kind of mislead into thinking GIT was the best option for this.

我是 GIT 的新手,到目前为止,我一直在使用 Visual Studio Online TFS 进行版本控制,而且我是唯一的开发人员。当我创建我的最后一个项目时,我有点误以为 GIT 是最好的选择。

So I checked-in my master. Then when I was going to work on a Feature I read I had to create a branch (this was not necessary in TFS) so I created "development_print" as a new branch and worked on my feature.

所以我签入了我的主人。然后当我要处理一个功能时,我读到我必须创建一个分支(这在 TFS 中不是必需的)所以我创建了“development_print”作为一个新分支并处理我的功能。

Now my feature is complete but I don't know how to merge it back into master. I am not interested in multiple branches at the moment, just want my new feature merged into master and remain with master.

现在我的功能已经完成,但我不知道如何将它合并回 master。我目前对多个分支不感兴趣,只想将我的新功能合并到 master 并保留在 master 中。

In VS there is a merge branchoption but it only allows me to merge into development_print (I want my feature into master!) so it does not let me set Into Current Branch and for Merge From Branch shows:

在 VS 中有一个合并分支选项,但它只允许我合并到 development_print(我希望我的功能进入 master!)所以它不允许我设置到当前分支和从分支合并显示:

  • Development_print
  • master
  • origin/development_print
  • origin/master
  • Development_print
  • 掌握
  • 起源/发展_打印
  • 起源/主人

which is kind of confusing? it seems all backwards. So how do I get out of this mess without losing all the work I did on the feature?

这有点令人困惑?似乎都倒退了。那么如何在不丢失我在该功能上所做的所有工作的情况下摆脱这种混乱呢?

回答by Marina Liu

The way to merge development_print branch into master branch as below:

将 development_print 分支合并到 master 分支的方式如下:

VS -> Team Explorer -> Branches -> double click master branch -> Merge -> select development_print for Merge from branch -> Merge.

VS -> Team Explorer -> Branches -> 双击 master 分支 -> Merge -> 选择 development_print for Merge from branch -> Merge。

The select box shows:

选择框显示:

development_print
master
origin/development_print
origin/master

That means you have branches development_printand masterfor both local and remote. origin/means branches exist in remote.

这意味着您有分支机构,development_print并且master适用于本地和远程。origin/意味着分支存在于远程。

If you don't want the development_printbranch after merging you can delete it for local and remote:

如果您development_print在合并后不想要该分支,则可以将其删除为本地和远程:

Team Explorer -> Branches -> select development_print -> right click -> Delete -> select development_print under remotes/origin -> Delete Branch From Remote.

团队资源管理器 -> 分支 -> 选择 development_print -> 右键单击​​ -> 删除 -> 在 remotes/origin 下选择 development_print -> 从远程删除分支。

回答by VonC

You can follow the Microsoft tutorial "Create work in branches".
Also, as shown in "Getting Used to Git in Visual Studio: Branches" from Jeremy Bytes (2014, but should still apply), you can go back to the "Branches" section and select "Merge".

您可以按照 Microsoft 教程“在分支中创建工作”进行操作。
此外,如Jeremy Bytes(2014,但仍应适用)的“在 Visual Studio 中使用 Git:分支”中所示,您可以返回到“分支”部分并选择“合并”。

This gives us drop-downs to fill in:

这为我们提供了用于填写的下拉列表:

https://4.bp.blogspot.com/-m3zHy1wthZA/VKIadAAXBqI/AAAAAAAADqY/0LczBDT-kOE/s1600/Merge.png

https://4.bp.blogspot.com/-m3zHy1wthZA/VKIadAAXBqI/AAAAAAAADqY/0LczBDT-kOE/s1600/Merge.png

You can see the branch section in "Microsoft Application Lifecycle Management", also used when you created your topic branch:

您可以在“ Microsoft Application Lifecycle Management”中看到分支部分,在您创建主题分支时也使用:

https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/45/92/2014/06/pull_2D00_requests/6242.VCtrlGitPullReqCreateTopicBranch.png

https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/45/92/2014/06/ pull_2D00_requests/6242.VCtrlGitPullReqCreateTopicBranch.png

回答by user11714042

In VS switch to master branch to be your current branch and from Team Explorer -> Branches you should get the Merge options in the right order where you will be able to select in the "Merge from branch" drop-down development_print branch and the "Into current branch" field will be preselected with master.

在 VS 中切换到 master 分支作为您当前的分支,并从 Team Explorer -> Branches 您应该以正确的顺序获得合并选项,您将能够在“从分支合并”下拉式 development_print 分支和“进入当前分支”字段将与 master 预选。