Information Technology Reference
In-Depth Information
How It Works
The command
$ git rebase --onto
operates on three branches:
$ git rebase --onto a b c
The first branch—
a
—is the branch onto which we will reapply the patches. Two
other branches define the set of patches to be reapplied. It will be the set defined by the
double dot operator
b..c
. In other words the command takes the revisions that are in-
cluded in
c
but not in
b
and reapplies them on top of
a
. If the operation is successful
then
c
is moved and points to the resulting commit.
The command shown in
Listing 7-4
can be executed in any branch. The result will
always be the same: the commits
b1
and
b2
will be reapplied as
b1'
and
b2'
on top
of the
master
branch. After the operation branch
c
will be your current branch.
In case you omit the last parameter, your current branch will be rebased. The fol-
lowing commands are equivalent:
$ git rebase --onto foo bar
$ git rebase --onto foo bar HEAD
We can say that the command from
Listing 7-4
is equivalent to two commands:
$ git checkout brave-idea
$ git rebase --onto master feature
7-6. Creating bulbs for divergent
branches
Problem
You repository looks like
Figure 7-11(a)
.
You want to merge the changes introduced in
the
feature
branch back into the
master
branch in such a way that reapplied revi-
sions
f1'
,
f2'
, and
f3'
form a bulb above the revision from the
master
branch.
The repository you wish to achieve is shown in
Figure 7-11(b)
.