Git Rebase引入了合并提交 [英] Git Rebase introducing a merge commit

查看:65
本文介绍了Git Rebase引入了合并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况:

  1. 支行
  2. 从分支A创建的
  3. 分支B说为commit CommitInitialA
  4. 我在分支B上做了一些提交,说 CommitB1 <- CommitB2
  5. 分支A并行获得一些提交,例如 CommitA1 <- CommitA2
  6. 我运行git rebase,以便分支B具有线性历史记录 CommitInitialA <- CommitA1 <- CommitA2 <- CommitB1 <- CommitB2
  7. 现在,将来,分支B获得新的提交,例如 CommitB3 ,并行地,分支A获得新的提交 CommitA3
  1. Branch A
  2. Branch B which is created from Branch A say as commit CommitInitialA
  3. I make a few commits on Branch B say CommitB1<-CommitB2
  4. Branch A gets some commits in parallel say CommitA1<-CommitA2
  5. I run git rebase so that branch B has a linear history CommitInitialA<-CommitA1<-CommitA2<-CommitB1<-CommitB2
  6. Now, in future, Branch B gets new commit say CommitB3 and in parallel Branch A get new commit CommitA3

这时,当我尝试再次在分支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屋!

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