tags:

views:

47

answers:

1

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 usually 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).

+1  A: 

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)

VonC
Right, that worked. `--onto` has 6 possible permutations, so I guess I didn't try the correct one.
asmeurer
@asmeurer: actually, considering `master` is the common ancestor of `my_WIP_branch` and `branch2`, a simple `git checkout my_WIP_branch` followed by `git rebase branch2` should have been enough.
VonC
@VonC, no, the problem was that `master` wasn't an ancestor of `branch2` (take another look at my diagram), and I wasn't ready to handle the merge conflicts involved with rebasing `branch2` over master.
asmeurer
@asmeurer: riiight. I get it now. I have edited my answer to better reflect the `master` state in relation with `branch2`. The `rebase --onto` is truly made for this kind of situation.
VonC