Hints and Topic for Merging Between Branches
How can I find out the basics of merging?
Read the official Subversion Manual which is well written and easy to understand.
How do I read an svn merge
command-line
First, see
the basics. Read it carefully.
Briefly, the way to read an
svn merge
command line is as follows. Example:
svn merge -r 8142:8143 http://svn.twiki.org/svn/twiki/branches/OMEN/bin
This says:
merge all changes that were made between rev 8142 and rev 8143 in the bin
directory of the OMEN
branch, to the working copy in the current directory.
This only makes sense if you are already cd'ed to the
bin
directory in your working copy. It also only makes sense if your working copy has already been updated as far as revision 8142. What is merged are the
differences between 8142 and 8143, so the changes that were applied to the previous rev to create 8142 will
not be merged.
The best way to find the starting rev for a merge is to
find the current rev of the working directory you are merging
to, and then merge all changes between that rev, and the rev on the branch you want to merge
from.
How do I merge the latest rev of my plugin from one branch to another?
Let's assume you want to merge "SparkPlugin" from "trunk" to "Myscratch".
Start by cd'ing to the directory you want to merge
to.
cd /home/twiki/trunk/SparkPlugin
Find out the range of revision numbers to merge.
- Check the
svn log
of the root directory in the Myscratch and find the checkin message for the last merge from MAIN.
svn log | grep -i merge
Let's say it's revision
1234. This is the
lower end of the merge range.
Now
find the latest rev of the directory you are mergeing
from (i.e. in the MAIN branch). Let's say it's 4321. This is the
upper end of the merge range.
Now we are ready to merge.
svn merge -r 1234:4321 http://svn.twiki.org/svn/twiki/trunk/SparkPlugin
This will print out where the merge has detected differences. If you now
svn diff
you can see what has changed.
Now, check in. It is critically important that you record
exactly what you just did. . Use
Item000
as the item for the merge unless there is an existing relevant item.
svn commit -m "Item000: svn merge -r 1234:4321 http://svn.twiki.org/svn/twiki/trunk/SparkPlugin"
How can I find out what the highest revision of a directory tree is?
The following command line will generate a sorted list of the revisions of all files in a subtree:
find . -name .svn -prune -o -print -exec svn status -v {} ; | sort -k 2
Refer to
svn help status
for details on what the fields are. The sort order is "last changed revision" so the lowest file on the list should be the most recently modified.
This command
does not go back to the subversion server, so make sure you
svn up
first.
How do I merge someone else's bugfix checkin?
Let's say someone has fixed
Item666
and checked the change into
OMEN
branch, and you want to merge that change
but only that change into
MAIN
branch.
Item666
says
SVN 4009
at the end and is
Status: Closed
Look in the checkin history (see the twiki-dev mail logs, which ought to be linked from here) for the checkin you are interested in. Either cross-reference the
SVN version number (4009) in the bug report, or search in the mail log for
Item666:
(better).
You should now have an
SVN version number (or a list of numbers representing the different stages of the checkin. Make a note of which files/directories were impacted by the checkin.
So, we have done that and now we know the change for
Item666
was committed in three stages as 4004, 4005 and 4009, and affected
templates/number.tmpl
and
tools/beast.bat
. We want all these changes.
svn merge
works by merging all the differences between the highest rev you give it, and the lowest rev you give it. So, we are actually interested in the changes between rev 4003 and rev 4005, and the changes between rev 4008 and 4009. We will do the merge in two steps, because we don't want to risk picking up the changes in 4006, 4007 or 4008.
cd /home/twiki/MAIN
svn merge -r 4003:4005 http://svn.twiki.org/svn/twiki/branches/OMEN/templates
svn merge -r 4008:4009 http://svn.twiki.org/svn/twiki/branches/OMEN/templates
svn merge -r 4003:4005 http://svn.twiki.org/svn/twiki/branches/OMEN/tools
svn merge -r 4008:4009 http://svn.twiki.org/svn/twiki/branches/OMEN/tools
Only
templates/number.tmpl
and
tools/beast.bat
should be changed. Check the changes using
svn diff
.
Note that if the changes in 4006, 4007 and 4008 affected a completely different set of files, it would be perfectly safe to combine the ranges, and merge from
4003:4009
.
Commit the changes. Make sure the commit comment is absolutely clear about what you did e.g.
svn commit -m "Item666: Merged bugfix versions 4004, 4005 and 4009 from OMEN branch" templates/number.tmpl tools/beast.bat
--
Contributors: CrawfordCurrie,
SvenDowideit
--++ Discussions
Tell me what's wrong with this syntax. To merge from DEVELOP to MAIN:
cd /Users/arthurclemens/Documents/MAIN/
/usr/local/bin/svn merge -r 8743 http://svn.twiki.org/svn/twiki/branches/DEVELOP/twikiplugins/PatternSkin/templates
I get this message:
merge: Apply the differences between two sources to a working copy path.
usage: 1. merge sourceURL1[@N] sourceURL2[@M] [WCPATH]
2. merge sourceWCPATH1@N sourceWCPATH2@M [WCPATH]
3. merge -r N:M SOURCE[@REV] [WCPATH]
--
ArthurClemens - 10 Mar 2006
Your command-line has a number of problems. See
how to read SVN command lines and -
important - read the red book chapter on merging, it really is
essential background.
In summary, your command line is wrong because:
- You need to be in the part of the working copy that corresponds to the URL.
- You need to give the other end of the rev range (you can use HEAD)
I think it's likely that the commands you want are:
cd /Users/arthurclemens/Documents/MAIN/twikiplugins/PatternSkin/templates
/usr/local/bin/svn merge -r 8743:HEAD http://svn.twiki.org/svn/twiki/branches/DEVELOP/twikiplugins/PatternSkin/templates
--
CrawfordCurrie - 10 Mar 2006