问题
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