开发者

Complex git rebase maneuver

开发者 https://www.devze.com 2022-12-31 20:14 出处:网络
Looking at the git-rebase man page, I didn\'t see any diagrams that looked like what I want (except some seem to do the reverse of what I want), and playing around with --onto didn\'t get me what I wa

Looking at the git-rebase man page, I didn't see any diagrams that looked like what I want (except some seem to do the reverse of what I want), and playing around with --onto didn't get me what I wanted either.

Let me see if I can draw a diagram like the ones from the git-rebase man page (the vertical bars to the left are to make Markdown format it correctly):

|      o-o-o-o-branch2
|     /
| -o-o-A-master-o-branch1-o-o-my_WIP_branch

branch1 is probably not actually important here, but I included it anyway. What I want to do is get this (omitting the 's that that usua开发者_StackOverflow中文版lly accompany the git-rebase man page diagrams):

|     o-o-o-o-branch2-o-branch1-o-o-my_WIP_branch
|    /
|-o-o-A-master

Basically, I want to put my my_WIP_branch work over the branch2 work without having to deal with merge conflicts involved in the group of commits labeled A. Is there any way to do this other than manually cherry-picking each commit over branch2 (or at least is there maybe an easy way to do that?)? By the way, there will be merge conflicts, so ideally it should be a git command or group of git commands that handle those gracefully (e.g., git rebase handles them gracefully, git am and git apply do not).


Strange... because this should be a classic case of rebase --onto.

You have:

     o-o-o-o <--branch2
    /
 o-o-o-A <--master
        \
         -o-o <--branch1
             \
              -o-o <--my_WIP_branch

You want:

                  -o-o <--my_WIP_branch
                 /
             -o-o <--branch1
            /
     o-o-o-o <--branch2
    /
 o-o-o-A <--master

That should be:

$ git rebase --onto branch2 master my_WIP_branch

it will replay any commit not on master, but from where you can reach my_WIP_branch (meaning the commits from branch2 are not eligible).
See my other SO answer for merge conflict instructions, and the "resolving merge conflicts" section of the Git manual. (you can accept all merges with your version, for instance)

0

精彩评论

暂无评论...
验证码 换一张
取 消