将一个本地分支合并到另一个本地分支 [英] merge one local branch into another local branch

查看:1375
本文介绍了将一个本地分支合并到另一个本地分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • 分支1:新的开发,还没有完全完成

  • Branch2:针对问题的修补程序,但仍在测试中

  • Branch3:分支周围的垃圾,我不会恢复



在修复程序测试完成之前,我希望代码已经在Branch1中可用,所以我可以继续使用修复程序进行开发。
(但是因为我对git的经验并不多,所以我首先开始在第三个分支中合并,特别是在混淆分支1或分支2之前创建的)。



在我的第三个分支中,我首先尝试了以下方法:

  git merge feature / Branch1 

但这给了以下错误:

 致命:'feature / Branch1'不指向提交

接下来我在Branch1中做了一个commit -a,然后再次尝试,但它一直给出同样的错误。



我做错了什么?我应该如何合并代码 - 在这种情况下 - Branch1与Branch3?

解决方案

首先,结账到您的Branch3:

  git checkout Branch3 

然后合并Branch1:

  git merge Branch1 

如果您想更新Branch2上的Branch1的提交,您可能正在寻找 git rebase

  git checkout Branch2 
git rebase Branch1

将使用Branch1的最新更新更新您的Branch2。


I have multiple branches which are branched off the master (each in a seperate subdirectory).

  • Branch1: new development, not yet completely finished
  • Branch2: hotfix for a problem, but still under test
  • Branch3: mess around branch, which I will not restore

Before testing of the hotfix is finished I would like to have the code already available in Branch1, so I can continue developing with the fix in place.
(But since my experience with git is not that much I first started to play around with merge in a 3rd branch, especially created to mess around in, before I mess up either Branch1 or Branch2)

In my 3rd branch I first tried the following:

git merge feature/Branch1

but this gave the following error:

fatal: 'feature/Branch1' does not point to a commit

I next did a commit -a in my Branch1 and tried again, but it keeps giving the same error.

What am I doing wrong? What should I do to merge the code from - in this case - Branch1 with Branch3?

解决方案

First, checkout to your Branch3:

git checkout Branch3

Then merge the Branch1:

git merge Branch1

And if you want the updated commits of Branch1 on Branch2, you are probaly looking for git rebase

git checkout Branch2
git rebase Branch1

This will update your Branch2 with the latest updates of Branch1.

这篇关于将一个本地分支合并到另一个本地分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆