2977.1.5
by Ian Clatworthy
added chapter on Sharing with a peer |
1 |
Merging changes |
2 |
=============== |
|
3 |
||
4 |
Parallel development |
|
5 |
-------------------- |
|
6 |
||
7 |
Once someone has their own branch of a project, they can make |
|
8 |
and commit changes in parallel to any development proceeding |
|
9 |
on the original branch. Pretty soon though, these independent |
|
10 |
lines of development will need to be combined again. This |
|
11 |
process is known as *merging*. |
|
12 |
||
13 |
The merge command |
|
14 |
----------------- |
|
15 |
||
16 |
To incorporate changes from another branch, use the ``merge`` command. |
|
17 |
Its syntax is:: |
|
18 |
||
19 |
bzr merge [URL] |
|
20 |
||
21 |
If no URL is given, a default is used, initially the branch this branch |
|
22 |
originated from. |
|
23 |
For example, if Bill made a branch from Mary's work, he can merge her |
|
24 |
subsequent changes by simply typing this:: |
|
25 |
||
26 |
bzr merge |
|
27 |
||
28 |
On the other hand, Mary might want to merge into her branch the work Bill |
|
29 |
has done in his. In this case, she needs to explicitly give the URL the |
|
30 |
first time, e.g.:: |
|
31 |
||
32 |
bzr merge sftp://mary@bill-laptop/cool-repo/cool-trunk |
|
33 |
||
34 |
This sets the default merge branch if one is not already set. To change the |
|
35 |
default after it is set, use the ``--remember`` option. |
|
36 |
||
37 |
How does merging work? |
|
38 |
---------------------- |
|
39 |
||
40 |
A variety of algorithms exist for merging changes. Bazaar's |
|
41 |
default algorithm is a variation of *3-way merging* which |
|
42 |
works as follows. Given an ancestor A and two branches B and C, |
|
43 |
the following table provides the rules used. |
|
44 |
||
3074.1.3
by Ian Clatworthy
more feedback from jameinel |
45 |
=== === === ====== ================= |
46 |
A B C Result Comment |
|
47 |
=== === === ====== ================= |
|
48 |
x x x x unchanged |
|
49 |
x x y y line from C |
|
50 |
x y x y line from B |
|
51 |
x y z ? conflict |
|
52 |
=== === === ====== ================= |
|
2977.1.5
by Ian Clatworthy
added chapter on Sharing with a peer |
53 |
|
54 |
Note that some merges can only be completed with the assistance |
|
55 |
of a human. Details on how to resolve these are given in |
|
56 |
`Resolving conflicts`_. |
|
57 |
||
58 |
Recording a merge |
|
59 |
----------------- |
|
60 |
||
61 |
After any conflicts are resolved, the merge needs to be committed. |
|
62 |
For example:: |
|
63 |
||
64 |
bzr commit -m "Merged Mary's changes" |
|
65 |
||
2977.1.11
by Ian Clatworthy
make fixes suggested by proof-readers |
66 |
Even if there are no conflicts, an explicit commit is still required. |
2977.1.5
by Ian Clatworthy
added chapter on Sharing with a peer |
67 |
Unlike some other tools, this is considered a feature in Bazaar. |
68 |
A clean merge is not necessarily a good merge so making the commit |
|
69 |
a separate explicit step allows you to run your test suite first to |
|
70 |
verify all is good. If problems are found, you should correct them |
|
71 |
before committing the merge or throw the merge away using ``revert``. |
|
72 |
||
73 |
Merge tracking |
|
74 |
-------------- |
|
75 |
||
76 |
One of the most important features of Bazaar is distributed, |
|
77 |
high quality *merge tracking*. |
|
78 |
In other words, Bazaar remembers what has been merged already and |
|
79 |
uses that information to intelligently choose the best ancestor for |
|
80 |
a merge, minimizing the number and size of conflicts. |
|
81 |
||
82 |
If you are a refugee from many other VCS tools, it can be really |
|
83 |
hard to "unlearn" the *please-let-me-avoid-merging-at-any-cost* habit. |
|
84 |
Bazaar lets you safely merge as often as you like with other people. |
|
85 |
By working in a peer-to-peer manner when it makes sense to do so, you |
|
86 |
also avoid using a central branch as an "integration swamp", keeping |
|
87 |
its quality higher. When the change you're collaborating on is |
|
88 |
truly ready for wider sharing, that's the time to merge and commit |
|
89 |
it to a central branch, not before. |
|
90 |
||
91 |
Merging that Just Works truly can change how developers work together. |