Instructions on branching and merging in CVS
NEW_FEATURE with what you're doing, duh. :)
sandboxis your checked-out copy of some module. It is assumed that you are at the location that you want to branch.
sandbox$ cvs tag NEW_FEATURE_ADD_ROOT
sandbox$ cvs tag -b -r NEW_FEATURE_ADD_ROOT \
NEW_FEATURE_ADD_BRANCH
sandbox$ cvs up -r NEW_FEATURE_ADD_BRANCH
You are now in the new branch, do what you want.
Occasionally, we all make mistakes and forget step 3 in
Creating the Branch
, and check things in on the
HEAD
revision instead of our new branch. Here are the steps to fix that.
sandbox$ cvs diff -u -r NEW_FEATURE_ADD_ROOT > accident.diff(Assuming that accident.diff doesn't exist already. If it does, choose a new name.)
sandbox$ patch -p0 -R < accident.diff
HEAD
back to the way you found it.
sandbox$ cvs ci
sandbox$ cvs up -r NEW_FEATURE_ADD_BRANCH
sandbox$ patch -p0 < accident.diff
sandbox$ cvs ci
Note:
The tag names have changed slightly. It is
very
important to use the prefixes
merge_
and
from_
appropriately, or your branches won't align nicely in
sandbox$ cvs tag merge_NEW_FEATURE_ADD
sandbox$ cvs up -A
sandbox$ cvs up -j NEW_FEATURE_ADD_BRANCH
This will list:
Files with conflicts will have conflict markers in them. Conflict markers look like:
<<<<<<< filename
your lines
=======
other person's lines
>>>>>>> current version
The new updates are now in your working directory. Even if you didn't get any conflicts, you have to verify that the CVS merge process didn't incorrectly merge your changes. Remember that just because CVS didn't find a direct conflict doesn't mean that the code logic is correct or that the program compiles, CVS knows nothing about the program or the programming language.
A quick way to open all the files that have conflicts (in Vim):
$ vim `cvs up -d | & grep '^C' | sed -e 's/^C //'`
sandbox$ cvs diff -uw
sandbox$ sudo make install(Or however you install and test your code)
sandbox$ cvs ci
sandbox$ cvs tag from_NEW_FEATURE_ADD
So, by now you may have figured out the magic of the merge_ and from_ tags. If not, here it is: They give you an anchor on where the changes happened, and they tell CVSGraph which way to draw the arrows (merge_ is the start of the arrow, from_ is the pointy end.) The name after merge_ and from_ don't matter, as long as they make sense (for what the branch does) and match.
If you're working on a branch, inevitably someone else checks in a change on the head (or merges another branch) adding functionality you want, or substantially changing code that you are about to (or have already) change.
To merge from the HEAD to your branch. (You can, of course, merge between branches, but depending on the branch-points, that can be tricky.) Another common usage is to merge from the branch to HEAD repeatedly, which I leave as an excercise to the reader (hint: you reverse the sources and targets in every step).
HEAD:
$ cvs up -A
HEAD where you are going to merge.
$ cvs tag merge_HEAD_NEW_FEATURE_ADDI use
HEAD_NEW_FEATURE_ADD to signify that it is merging HEAD to NEW_FEATURE_ADD.
$ cvs up -r NEW_FEATURE_ADD_BRANCH
$ cvs up -j HEAD
VERY IMPORTANT -- This records where the merge happened and is essential for when you want to merge again.
$ cvs tag from_HEAD_NEW_FEATURE_ADD
If you want to merge from HEAD again, you can, just use another tag name, for example HEAD_NEW_FEATURE_ADD2:
$ cvs up -A
$ cvs tag merge_HEAD_NEW_FEATURE_ADD2
$ cvs up -r NEW_FEATURE_ADD_BRANCH
$ cvs up -j merge_HEAD_NEW_FEATURE_ADD -j HEAD
NOTE: the tag following the first -j is the previous merge tag.
This tells CVS to merge changes that were added between the two tags.
$ cvs tag from_HEAD_NEW_FEATURE_ADD2
Now you probably realize why this tag is important, without it you have nowhere to anchor to in step 4.
One branch in CVS (even HEAD) can be replaced with another using a similar syntax to a merge.
sandbox$ cvs tag merge_NEW_FEATURE_ADD
HEAD, or to the branch you want to
REPLACE:
HEAD:
sandbox$ cvs up -A
sandbox$ cvs up -r ANOTHER_BRANCH
HEAD:
sandbox$ cvs up -jHEAD -j NEW_FEATURE_ADD_BRANCH
sandbox$ cvs up -jANOTHER_BRANCH -j NEW_FEATURE_ADD_BRANCH
sandbox$ cvs ci
sandbox$ cvs tag from_NEW_FEATURE_ADD
| Keywords: | branching merging cvs replace branch merge | Doc ID: | 4087 |
|---|---|---|---|
| Owner: | Jon M. | Group: | Middleware |
| Created: | 2005-10-20 | Updated: | 2007-01-25 |