git更改父分支 [英] git change the parent branch

查看:160
本文介绍了git更改父分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短的故事是:我已经从 Develop 分支中创建了 A 分支然后我从分支 A

The short story is : I have created Branch A out from the Develop Branch then I created Branch B From Branch A

我们稍后决定在下一个版本中需要包含分支B,而将不包含分支

We decided later that we need to include the branch B in the next release and A will not be included

我打算做的是:

  1. 删除我对B的第一个拉动请求
  2. 从Develop分支创建一个新的分支B1
  3. 樱桃选择我需要的提交
  4. 然后删除旧的B分支
  5. 将B1重命名为B
  6. 为新的分支B创建拉取请求

所以我在想是否可以将B分支的父级更改为 Develop 而不是 A 以避免这种混乱

so I was thinking if there is a way to change the parent of B branch to be Develop instead of A to avoid this mess

推荐答案

假设您当前的分支图看起来像这样:

Let's say that your current branch diagram looks something like this:

develop: A -- B
               \
branchA:        C -- D -- E
                           \
branchB:                    F -- G

您希望B分支看起来像这样:

You want the B branch to look like this:

develop: A -- B
               \
branchB:        F -- G

在此可以使用基准重设:

Rebase onto can be used here:

git rebase --onto B E

用简单的英语术语来说,以上命令说将父代为 E 的提交(即 F 提交(以及B分支的开始))放置到一个新的基础,它是在 develop 分支中提交 B 的地方.

In plain English terms, the above command says to place the commit whose parent is E, which is the F commit (and the start of the B branch) onto a new base which is commit B in the develop branch.

这篇关于git更改父分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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