我如何重塑一系列本地git分支? [英] How do I rebase a chain of local git branches?
问题描述
master branch1 branch2
| | |
o ---- o ---- o ---- A ---- B ---- C ---- D
我将一个上游变更引入主分支:
branch1 branch2
| |
A ---- B ---- C ---- D
/
o ---- o ---- o ---- o
|
master
现在我分支branch1,给我这个:
branch2
|
A ---- B ---- C ---- D
/
o ---- o ---- o ---- o ---- A '--- B'
| |
master branch1
请注意,由于分支branch1,提交A和B已被重写为A'和B'。
这是我的问题:现在我想分支branch2。显而易见的语法是 git rebase branch1 branch2
,但这绝对不起作用。我想要它做的只是在branch1上重新应用C和D,但它试图调和A和A',并认为它们是冲突的。
这样做工作:
git rebase --onto branch1 branch2 ^^ branch2
这个假设我知道branch2在前一个分支1 ref之后只有2个提交。
由于 git rebase --onto
有效,是否有一条1行的git命令可以将branch2重新绑定到新重建的分支上1,这种方式我不必准确地知道有多少次提交是branch2的一部分? (我想指定一些magic ref而不是branch2 ^^作为中间参数。)
或者有其他方法可以忽略吗?
我最感兴趣的是可以适用于极端情况的解决方案,而不仅仅是两个分支 - 假设我有更像5个本地分支的东西,所有东西都链接在一起,而我希望将所有这些材料重新组合在一起。
单行:
git rebase --onto branch1 branch1tmp branch2
假设在 那被说,请检查 所以检查这是否可行(并且缩放比较好): Suppose I have a chain of local git branches, like this: I pull in an upstream change onto the master branch: Now I rebase branch1, giving me this: Note that because of rebasing branch1, commits A and B have been rewritten as A' and B'. Here's my problem: now I want to rebase branch2. The obvious syntax is This does work: This assumes I know that branch2 has exactly 2 commits beyond the previous branch1 ref. Since Or is there some other approach I'm overlooking? I would be most interested in a solution that scales well to extreme cases, not just two branches - suppose I've got something more like 5 local branches, all chained on one another, and I want to rebase all of them together. One-line: That supposes to make a
That being said, check what So check if this would work (and scale better):
这篇关于我如何重塑一系列本地git分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!分支1
之前制作 branch1tmp
code $。
$ b $ pre $ git checkout branch1
git分支branch1tmp
git rebase master
git rebase --onto branch1 branch1tmp branch2
ORIG_HEAD
引用。
从:
ORIG_HEAD
已设置在复位之前指向分支的尖端。
git checkout branch1
git rebase master
git rebase --onto branch1 ORIG_HEAD branch2
git rebase --onto branch2 ORIG_HEAD branch3
...
master branch1 branch2
| | |
o----o----o----A----B----C----D
branch1 branch2
| |
A----B----C----D
/
o----o----o----o
|
master
branch2
|
A----B----C----D
/
o----o----o----o----A'---B'
| |
master branch1
git rebase branch1 branch2
, but that definitely does not work. What I want it to do is just reapply C and D on top of branch1, but instead it tries to reconcile A and A' and it considers them conflicting.git rebase --onto branch1 branch2^^ branch2
git rebase --onto
works, is there a 1-line git command that will rebase branch2 on top of a newly-rebased branch1, in a way that I don't have to know exactly how many commits were part of branch2? (I want to specify some magic ref instead of branch2^^ for the middle argument.)git rebase --onto branch1 branch1tmp branch2
branch1tmp
on branch1
before rebasing branch1
.git checkout branch1
git branch branch1tmp
git rebase master
git rebase --onto branch1 branch1tmp branch2
ORIG_HEAD
references.
From git rebase man page:
ORIG_HEAD
is set to point at the tip of the branch before the reset. git checkout branch1
git rebase master
git rebase --onto branch1 ORIG_HEAD branch2
git rebase --onto branch2 ORIG_HEAD branch3
...