Rebase a merge commit

回眸只為那壹抹淺笑 提交于 2019-11-30 06:53:57

I realize this is quite an old topic but since I found this question while facing a similar situation I could as well tell what I used in the end.

git checkout FooBar
git rebase -p --onto Foo A

I tried to use the names from the original question. Note especially that A means the commit that is marked as A in the ascii art. You would probably use the hash of the commit instead or any other way to point to the commit where branches Foo and FooBar originally separate.

The -p flag is also known as --preserve-merges and it does pretty much what it says.

Note that the branch Bar doesn't play a role here so that line of commits might be a named branch or then not - it makes no difference.

Andy

You couldn't rebase under branch FooBar without changing what defines FooBar. What you could do is merge FooBar and Foo. That would have the same contents that you desire.

You're basically trying to erase all traces of the previously made merge.

If you truly want to throw away all commits that only exists in FooBar (and in the working directory), then proceed as follows: first do git checkout FooBar, then make git forget about it's history and do git reset --hard Foo (if you intent to merge Bar into Foo). Then you recreate the merge with git merge Bar.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!