在master上提交后git更新分支 [英] git update branch after commit on master

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

问题描述

我有以下回购结构:

  MA --- o --- o --- o --- T1- 
|
B1 \ --- o--
|
B2 \ --- o --- o

其中 MA master B1 B2 是分支, o 是提交, - 是开发, T1 是某个时间点



现在你看到,在我对 MA 进行了第一次提交之后,我创建了一个新分支 B1 。然后在 B1 上工作,然后创建 B2 并开始处理它。



现在我的问题是,在创建分支之后,我对 MA 做了两次更多的提交。但我希望整个分支发生在 T1 - 这样我的 B1 所有3个主提交都作为基础。

这里有两个问题:


  1. 有没有一些to repoint B1

  2. B2 如果我管理 repoint B1 ?我想保留 B2 B1 为基础提交的事实


解决方案

当然:rebase B1 ,然后 B2

您只需在做之前标记旧的B1状态:

  git checkout B1 
git branch oldB1
git rebase MA

B2 不变:

  MA --- o-- -o --- o --- T1 --- o B1 
|
oldB1 \ --- o
|
B2 \ --- o --- o

现在一个 rebase --onto 将移动 B2 提交( oldB1 头部之一 - 排除 - 高达 B2 HEAD - 包括 - )。

  git checkout B2 
git rebase --onto B1 oldB1 B2
git branch -d oldB1

这将给出:

  MA --- o --- o --- o --- T1 --- o B1 
|
B2 \ --- o --- o


I have the following repo structure:

MA ---o---o---o---T1-
        |
B1      \---o--
              |
B2            \---o---o

where MA is master, B1 and B2 are branches, o is commit, - is development and T1 is some time point

Now you see that after I did the first commit on MA, I created a new branch B1. Then worked on B1, then created B2 and worked on it as well.

My problem is now that I did two more commits on MA after I have created the branches. But I want that the whole branching happens at time T1 - so that my B1 have all 3 master commits as basis.

So couple of questions here:

  1. Is there some (easy) way to repoint B1?
  2. What is going to happen to B2 if I manage to repoint B1? I want to preserve the fact that B2 has the commit on B1 as basis

解决方案

Sure: rebase B1, then B2.
You only needs to mark the old B1 state before doing it:

git checkout B1
git branch oldB1
git rebase MA

At this staged, B2 is unchanged:

MA ---o---o---o---T1---o B1
        |
oldB1   \---o
             |
B2           \---o---o

Now a rebase --onto will move B2 commits (the one between the oldB1 HEAD -- excluded -- up to B2 HEAD -- included --).

git checkout B2
git rebase --onto B1 oldB1 B2
git branch -d oldB1

That will give:

MA ---o---o---o---T1---o B1
                       |
B2                     \---o---o

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

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