Git 如何从具有更改提交的分支重新设置基础?

Git 如何从具有更改提交的分支重新设置基础?,git,Git,最初我是这样开始的: Branch A: Commit A1 Commit M9 Branch B: Commit B1 Commit M9 然后我做了: git checkout B git rebase A git checkout A // then I modified the branch and then I did git commit -a --amend 我的结局是: Branch A: Commit A1 Comm

最初我是这样开始的:

Branch A:    
  Commit A1  
  Commit M9

Branch B:   
  Commit B1  
  Commit M9
然后我做了:

git checkout B
git rebase A
git checkout A
// then I modified the branch and then I did
git commit -a --amend
我的结局是:

Branch A:    
  Commit A1
  Commit M9

Branch B:   
  Commit B1  
  Commit A1
  Commit M9
然后我做了:

git checkout B
git rebase A
git checkout A
// then I modified the branch and then I did
git commit -a --amend
现在我的分支机构的状态是

Branch A:    
  Commit A1
  Commit M9

Branch B:   
  Commit B1  
  Commit A1
  Commit M9

Note that now Commit A1 is actually different in both branches.
如何使用
分支A
中的新
提交A1
更新
分支B

您可以执行以下操作:

git checkout B
git rebase -i A
当文本编辑器打开时,删除与“old A1”提交(位于分支B中)对应的行

通常情况下,您不应该有冲突需要处理,除非B1基于您在修改中更改的同一代码(但它应该更容易处理)

您可以执行以下操作:

git checkout B
git rebase -i A
当文本编辑器打开时,删除与“old A1”提交(位于分支B中)对应的行


通常情况下,您不应该有冲突需要处理,除非B1基于您在修改中更改的同一代码(但它应该更容易处理)

你需要重新设定基准,但失败得很惨。大量冲突如果你的
旧A1→ 新A1和旧A1→ B1
以不同方式更改公共部分,您运气不佳,必须解决冲突:(啊,这很不幸,我希望能有一些git魔法,但我想这是有道理的,我运气不好!你也可以使用交互式重基删除分支B上的
A1
,然后重新进行重基。你需要重新进行重基。这失败得很惨。如果你的
旧A1→ 新A1和旧A1→ B1
以不同的方式更改公共部分,你运气不好,必须解决冲突:(啊,这很不幸,我希望有一些git魔法,但我想这是有道理的,我运气不好!你也可以使用交互式重基删除分支B上的
A1
,然后再次进行重基。