简体   繁体   中英

Rebase a merge commit when parents changed

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM