Information Technology Reference
In-Depth Information
• How to find a difference
a - b
of two branches, that is, revisions that are
included in branch
a
but excluded from branch
b
?
• How to find a symmetric difference
a ∆ b
of two branches, that is, revi-
sions that are included in either
a
or
b
but not in both?
• How to find revisions included in branches
a
,
b
, and
c
and excluded from
d
,
e
, and
f
?
The common ancestor of two branches is the latest revision included in two
branches. For branches
feature
and
brave-idea
it is
f3
. For
master
and
fea-
ture
it is
m3
. You can find the common ancestor using:
$ git merge-base feature brave-idea
If you want to get the common ancestor for more than two branches, use
--oc-
topus
parameter. The command:
$ git merge-base --octopus feature brave-idea master
prints the SHA-1 of
m3
commit.
The range of commits was already discussed in Recipe 7-2. A special operator
..
is
interpreted as a difference of branches. The command:
$ git log --oneline master..brave-idea
prints commits
b2
,
b1
,
f3
,
f2
, and
f1
, while:
$ git log feature..master
outputs revisions
m4
and
m5
.
The set of new commits introduced by two branches is resolved by the
...
operat-
or. It is a symmetrical difference of branches. The output of:
$ git log feature...brave-idea
consists of
f6
,
f5
,
f4
,
b2
, and
b1
.