When git rebasing two branches with some shared history, is there an easy way to have the common history remain common?

前端 未结 2 862
情深已故
情深已故 2020-11-29 05:31

Suppose we have the following revision graph:

A-X-Z--B
     \\
      \\-C

with A preceding both B and C. Further suppose I rebase A from up

2条回答
  •  眼角桃花
    2020-11-29 06:12

    git rebase --committer-date-is-author-date --preserve-merges --onto A* A C
    git rebase --committer-date-is-author-date --preserve-merges --onto A* A B
    

    This should keep the common commits having the same sha1 and any merges preserved. Preserve merges is not required in this case, but will become an issue with a less trivial history.

    To do this for all branches that contain A in their history do:

    git branch --contains A | xargs -n 1 git rebase --committer-date-is-author-date --preserve-merges --onto A* A 
    

    Hope this helps.

    UPDATE:

    This may be cleaner syntax:

    for branch in $(git branch --contains A); do git rebase --committer-date-is-author-date --preserve-merges --onto A* A $branch; done
    

提交回复
热议问题