Git Rebase引入了合并提交 [英] Git Rebase introducing a merge commit
问题描述
我有以下情况:
- 支行 从分支A创建的
- 分支B说为commit
CommitInitialA
- 我在分支B上做了一些提交,说
CommitB1
<-CommitB2
- 分支A并行获得一些提交,例如
CommitA1
<-CommitA2
- 我运行git rebase,以便分支B具有线性历史记录
CommitInitialA
<-CommitA1
<-CommitA2
<-CommitB1
<-CommitB2
- 现在,将来,分支B获得新的提交,例如
CommitB3
,并行地,分支A获得新的提交CommitA3
- Branch A
- Branch B which is created from Branch A say as commit
CommitInitialA
- I make a few commits on Branch B say
CommitB1
<-CommitB2
- Branch A gets some commits in parallel say
CommitA1
<-CommitA2
- I run git rebase so that branch B has a linear history
CommitInitialA
<-CommitA1
<-CommitA2
<-CommitB1
<-CommitB2
- Now, in future, Branch B gets new commit say
CommitB3
and in parallel Branch A get new commitCommitA3
这时,当我尝试再次在分支A上重新建立分支B的基础时,我发现分支B中有一个来自 CommitInitialA
的合并提交,而不是线性历史记录.
At this point when I try to rebase branch B again on branch A, I see that there is a merge commit in Branch B from CommitInitialA
instead of a linear history.
我应该如何第二次使用rebase,这样我就不会得到合并提交,而是得到线性历史记录?
How should I use rebase the second time so that I don't get a merge commit but instead a linear history?
基本上是在上述步骤6之后的第二次变基之后 CommitInitialA
<- CommitA1
<- CommitA2
<- CommitA3
<- CommitB1
<- CommitB2
<- CommitB3
Essentially after 2nd rebase after Step 6 above, I want
CommitInitialA
<-CommitA1
<-CommitA2
<-CommitA3
<-CommitB1
<-CommitB2
<-CommitB3
推荐答案
您可以尝试一下,如果没有冲突,就不会有问题:
You can try this and see that there is no issue if no conflict :
git init
git checkout -b branchA
touch inita testb1 testb2 testb3 testa1 testa2 testa3
git add inita
git commit -m "commitInitialA"
git checkout -b branchB
git add testb1
git commit -m "commitB1"
git add testb2
git commit -m "commitB2"
git checkout branchA
git add testa1
git commit -m "commitA1"
git add testa2
git commit -m "commitA2"
此时:
第一个变基:
git checkout branchB
git rebase branchA
其他提交:
git add testb3
git commit -m "commitB3"
git checkout branchA
git add testa3
git commit -m "commitA3"
此时:
第二个变基:
git checkout branchB
git rebase branchA
这篇关于Git Rebase引入了合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!