SVN Workout 1 – Branch and merge practise

RECOMMENDED TO USE LATEST SVN CLIENT, 1.8.4 (at time of writing)

Version control is only as good as how it’s used. And it can be used really badly. All the facilities are there to prevent trouble from occurring, but only if you use them.

A basic reliable version control workflow assumes that the trunk copy contains only stable production ready code.

To ensure only stable production ready code goes into the trunk, branches must be created to contain the work for each feature for a future release. Let’s say that again:

To ensure only stable production ready code goes into the trunk, branches must be created to contain the work for each feature for a future release.

It’s often tempting to just use the trunk for everything, avoid branching and merging to save time and hassle but that leads to bigger problems down the line and costs MORE time to later fix.

So to dispel the rumour that branching and merging is difficult, let’s do a little svn workout to show how easy it can be, and how much hassle it can save when real world problems occur.

Bringing back a deleted file or directory in svn

brings the file back but for inspection only. It doesn’t give option to commit or appear in the actual repository head.

Instead use :

eg:

Reverting a file back to a previous revision

svn revert only reverts uncommitted modifications made to a file in your local working copy.

If you want to time travel a file back to previous revisions you use svn merge

eg revert file foo.php to revision 100:

Subversion branching and tagging with Eclipse

Branching to complete a task outside the trunk in Eclipse

Creating the branch
  • Select the trunk working copy
  • Team/Branch/tag…
  • Copy to URL: Use the select button if the branch already exists, otherwise specify new directory in branches
  • Specify copy to be either HEAD or specific revision
  • Specify message for the branch, probably task name
  • When checking out a freshly created branch may have to right click a repository and select refresh before it appears

Checkout the branch to a fresh working copy
  • Can either checkout a fresh copy or switch your current working copy to the branch
  • Checkout fresh copy with New/Project…/SVN/Checkout Projects from SVN
  • Switch a current working copy using Team/Switch to another branch/revision…
Merging any changes from the trunk into your branch
  • Select the branch project directory
  • Update to HEAD
  • Team/Merge…
  • Select ‘Merge a range of revisions’
  • Merge from: /trunk
  • Revisions: All eligible revisions
  • Default conflict options (safest)
  • Any conflicts are flagged and should be dealt with manually
  • Commit

Command line version is a bit more tricky, the revisions to merge must be found manually

 

Branch task completed, merging branch back into the trunk
  • Select the trunk project directory
  • Update to HEAD
  • Team/Merge…
  • Select ‘Reintegrate a branch’
  • Here may get an error if the trunk hasn’t been updated. Update to HEAD
  • Merge from: <branch to merge>
  • Default conflict options (safest)
  • Any conflicts are flagged and should be dealt with manually
  • Commit

 

Tagging a release in Eclipse

All final releases are tagged with name <project><version>

All release candidates are tagged with name <project><version>_rc<release candidate integer version>

  • Select the trunk project directory
  • Team/Branch/tag…
  • Copy to URL: Use the select button if the tag already exists, otherwise specify new directory in tags
  • Specify copy to be either HEAD or specific revision
  • Specify message for the tag, probably version of release
  • When checking out a freshly created tag may have to right click a repository and select refresh

Subversion admin tasks

====Subversion admin tasks====

Stripping out all subversion files from a filesystem. Do this before moving content between filesystems under version control or final packaging:

===Getting subversion to ignore files===

This ensures files that are not part of the working copy are no automatically added in some IDE’s or listed in svn status

First ensure your shell is using a sensible editor, like vi

Now cd to the directory where the file is located.

Run the propedit command passing the property to edit, svn:ignore and the directory to work on – ‘.’ for the parent directory

And list all files to be ignored for that directory. Not paths do not work, only filenames. In other words you cant list all the files as paths in the root directory of the site.