在单个谱系中对多个分支进行基础定位的最简单方法 [英] Easiest way to rebase multiple branches in a single lineage

查看:52
本文介绍了在单个谱系中对多个分支进行基础定位的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支,保持在上游/主服务器上.一个分支将另一个作为祖先,因此它们形成一条线.

I have a two branches that I keep on top of upstream/master. One branch has the other as an ancestor so they form a line.

U1 (upstream/master)
  \
   A -- B (fixes)
         \
          C -- D (features)

后来,上游/母带向前移动...

Later, upstream/master moves forward...

U1 -- U2 (upstream/master)
  \
   A -- B (fixes)
         \
          C -- D (features)

...,我想将两个分支都重新置于顶部.

... and I want to rebase both branches on top.

U1 -- U2 (upstream/master)
        \
         A' -- B' (fixes)
                 \
                  C' -- D' (features)

我知道这样做的两种方法,每种方法都有缺点.

I know two ways to do it, each with drawbacks.

git rebase upstream/master fixes
git rebase fixes features

这两个命令有时会起作用,有时会给我第二个命令的合并冲突.

These two commands sometimes work and sometimes give me merge conflicts on the second command.

git rebase upstream/master features
# figure out the hash code of the new commit corresponding with B'
git branch -f fixes <sha of B'>

这仅涉及一个基础,但是移动分支很繁琐且容易出错.

This only involves a single rebase, but moving the branches is tedious and error prone.

我研究了rebase --preserve-merges,但这似乎不适用,因为没有合并提交.

I looked into rebase --preserve-merges, but that doesn't seem applicable because there are no merge commits.

有没有更好的方法来完成变基?

Is there a better way to accomplish the rebase?

推荐答案

避免合并冲突的一种方法是将分支从重新基准化前的历史记录移至重新基准化后的历史记录.公认这很糟糕,因为它需要弄清楚每次提交的新版本,但可能比不必要的合并要快.

One way to avoid the merge conflicts is to move the branches from the pre-rebase history to the post rebase one. This is admittedly terrible because it requires figuring out the new version of each commit, but might be faster than merging unnecessarily.

例如

git为上游/主功能重新设置

git rebase upstream/master features

U1 -- U2 (upstream/master)
        \
         A' -- B' 
                 \
                  C' -- D' (features)

git branch -f修复(B'的SHA))#更改分支指向的位置.

git branch -f fixes (SHA for B') # Change where the branch is pointing.

U1 -- U2 (upstream/master)
        \
         A' -- B' (fixes)
                 \
                  C' -- D' (features)

这篇关于在单个谱系中对多个分支进行基础定位的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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