Rebase a merge commit when parents changed

两盒软妹~` 提交于 2019-12-13 16:10:01

问题


Given a gerrit changeset which depends on two other, independent changesets:

P1-
   \
P2----C

gerrit represents this as a merge commit with two parents. Unlike normal merge commits though, it will contain nontrivial changes that are not related at all to the changes in the parents.

The parent changesets are updated in gerrit, so we have commits P1' and P2', which are amended versions of P1 and P2, modified based on code review feedback. What is the easiest way of producing C' which is a merge commit with parents P1' and P2', and contains the same changes (relative to its parents) as C?


回答1:


The closest I have gotten so far is to use rebasing to create a commit with the right parents and commit, but without the contents of the original commit:

git checkout C
git rebase --preserve-merges --onto P1' P1
git rebase --preserve-merges --onto P2' P2

...then manually apply all the changes in C, as shown by git show C. Having a way to transform the output of git show (a combined diff) into a normal diff would make it possible to automate this - I have asked that as a separate question: Transform a combined diff into a patch



来源:https://stackoverflow.com/questions/23923881/rebase-a-merge-commit-when-parents-changed

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