Subversion -- Copying Changes Between Branches

Copying specific changes between branches is covered well in Chapter 4 of Version Control With Subversion, but I thought a real-life example might be helpful to some people.

I use version control for mantaining the PHP code for the Computational Lingustics database. I made a small, cosmetic change to the table-generating code in a file called searchcorpus.php, in the trunk branch. I wanted to backport it to release-2.2. Here is the sequence I used. Throughout this procedure my current directory was inside my working copy of release-2.2.

Step 1: Locate the correct revision number.

$ svn log svn://
r196 | brodbd | 2007-10-25 15:31:05 -0700 (Thu, 25 Oct 2007) | 1 line

searchcorpus.php: Improve look of tables by inserting   instead of empty fields.
r106 | brodbd | 2007-10-16 16:38:04 -0700 (Tue, 16 Oct 2007) | 1 line

Now I know I want revision 196.

Step 2: Merge in the change.

$ svn merge -c 196 svn://
U    searchcorpus.php

This pulled in the changes to searchcorpus.php from revision 196 (and only revision 196) of trunk and applied them to my working copy. I then ran svn diff searchcorpus.php to make sure the merge did what I wanted. If not, I could have used svn revert to back out the changes.

Step 3: Commit the change.

$ svn commit -m "searchcorpus.php: Backport cosmetic fixes from trunk r196."
Sending        searchcorpus.php
Transmitting file data .
Committed revision 197.

Notice that my commit message indicates I'm importing changes from a specific revision number of another branch. This kind of bookkeeping is important in a complex project to make sure you don't accidentally merge the same change twice.

While this case is a simple one involving only one file, this same concept works for revisions that encompass multiple files or even whole directory trees, including file additions or deletions. This gives svn merge a bit of an edge over svn diff followed by patch when porting complicated changes.

-- DavidBrodbeck - 25 Oct 2007

Topic revision: r1 - 2007-10-25 - 23:03:07 - DavidBrodbeck

This site is powered by the TWiki collaboration platformCopyright & by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Privacy Statement Terms & Conditions