重新建立一个拥有子分支的分支 [英] Rebase a branch that has child branches

查看:96
本文介绍了重新建立一个拥有子分支的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司的政策是,任何拉取请求必须由重新设计的分支完成。我有一个本地Dev分支,它有'任务'分支:

  remote master -------- 
\
Dev ------------------
\ ----- task1 \
\ ---任务2

当主人更新时,什么是管理分支task1和task2的最佳方式。他们仍在努力。重新配置每个任务分支似乎是我能看到的唯一方式。

解决方案

如果你有很多任务分支,那么我能想到的最好的方法就是暂时章鱼将它们与Dev合并临时分支,然后使用--preserve-merges将临时分区重新分配给主分区。然后重新设置分支标签到适当的位置。

  $ git checkout -b temp Dev&& git merge task1 task2 
$ git rebase master --preserve-merges
$ git checkout Dev&& git reset --hard temp ^
$ git checkout task1&& git reset --hard temp ^ 2
$ git checkout task2&& git reset --hard temp ^ 3
$ git branch -D temp

它仍然是很多命令,但是:


  1. 由于树本质上是保留的,所以它不需要手动重构图形,即由于必须将每个任务分支移植到重新设计的Dev分支的适当的相应提交上,因此减少了人为错误。这只是将Dev和任务分支标记重置到正确的父提交上,这与它们在章鱼合并中使用/命名的顺序相对应。

  2. 如果你必须做很多这样的事情,这应该是简单的脚本和用作别名。



My company's policy is that any pull request must be done with a rebased branch. I have a local Dev branch and this has 'task' branches:

remote master --------
     \   
     Dev ------------------
            \-----task1  \
                          \---task2

When master gets updated, I rebase Dev on master. What is a optimal way to manage branches task1 and task2. They are still being worked on. Rebasing each task branch seems like the only way I can see.

解决方案

If you have a lot of task branches, then the best I can think of is to temporarily octopus merge them with Dev into a temp branch and then rebase temp onto master with --preserve-merges. Then reset the branch labels to the proper places.

$ git checkout -b temp Dev && git merge task1 task2
$ git rebase master --preserve-merges
$ git checkout Dev   && git reset --hard temp^
$ git checkout task1 && git reset --hard temp^2
$ git checkout task2 && git reset --hard temp^3
$ git branch -D temp

It's still a lot of commands, but:

  1. Since the tree is inherently preserved, it saves you from having to manually reconstruct the graph, i.e. less human error from having to graft each task branch onto the proper corresponding commit of the rebased Dev branch. It's just a matter of resetting the Dev and task branch markers onto the correct parent commit, which corresponds to the order they were used/named in the octopus merge.

  2. If you have to do this kind of thing a lot, this should be straightforward to script and use as an alias.

这篇关于重新建立一个拥有子分支的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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