Do a retroactive branch in CVS

You have a source tree that is not branched, and you suddenly need to get a previous version (maybe it is in production at that point, but the trunk has moved on since and is waaaaaaaaaaaay out of sync). What to to? Well if you could branch from back then, back in time to that revision …. well you get the idea, and I am calling this a retroactive branch, because instead of the branch being a the current revision or HEAD, it is from some date/revision/point in the past.

This is something that I sometimes find I must do with CVS but seems to be a bit of an obscure function, as there are not a lot of posts about it online. Therefore I am going to post about it here.

Here are the steps, I use, to do a retroactive branch in CVS.

1) Checkout using the tag for the previous revision that you want to start
a branch from.

for example:

    cvs co -r MY_TAG_V01-1 com/example/myapp/build.xml

2) Find out the date according to CVS for the tagged revision
I use “cvs log” to see the date of the tagged revision I wanted

for example:

  cd com/example/myapp/
  cvs log build.xml

In the result I see that my revision for this tag was 1.4 and the date was:
1970/01/01 01:00:00 (this is UTC I assume)

If your doing a bunch of files, then find the most recent date and use that. You can find a date that is older than the most recent date in the files you want to retro branch, and not as recent as any next revisions and use that.
3) Add a branch tag based on the date
an example, for one file:

    cvs tag -D "1970-01-01 01:00:00+00" -b branch_tag build.xml

or for many files:

    cvs tag -D "1970-01-01 01:00:00+00" -b branch_tag build.xml

That is it. Whala. In your favorite cvs app you should see your a new revision history for your source tree. I use ViewCVS and after doing these steps on a file in the source tree, then navigating to that tree and using the "Show files using tag" select control, I can see my "branch_tag" tag and chosing that tag to view by, I see a whole new revision history for my test file.

cvs update -r branch_tag updates only the new revision with the sub-revision

editing the source just given a new branch and commiting again creates new sub-revisions,

for example:

cvs commit
cvs commit: Examining .
Checking in build.xml;
/var/lib/cvsroot/com/example/myapp/build.xml,v  <--  build.xml
new revision: 1.4.4.1; previous revision: 1.4
done
Follow

Get every new post delivered to your Inbox.