Popular SVN commands used when deploying a website

tyrus-svn2This tutorial mentions about common tasks that we need to do when deploying a website to server using subversion (SVN commands). This assumes that we understand how to install svn client to the server, and understand some basic commands in according operating systems (Windows, Linux, etc.)

Checkout a new project

  • Cause: You want to deploy a new project from SVN repository.
  • Solution: Use svn co to perform this work (remember to have the dot (.) character at the end to checkout the project to current directory):
    sh-4.1$ svn co http://www.your-svn-repo.com/svn-project-directory .

Update a your source code

  • Cause: You want to update latest source code version from your repository to current directory.
  • Solution: Use svn up to perform this work. We can also update only one source file as follows:
    sh-4.1$ svn up index.php

Commit your modified files / folder to SVN repository

  • Cause: Sometimes you need to apply quick fix on production, so you want to commit this file back to SVN repo.
  • Solution: Use svn commit to perform this work. We can also update only one source file as follows:
    sh-4.1$ svn commit index.php -m "Your Commit Message"

Revert a file / directory to a previous revision

  • Cause: you accidentally update to the last version, but then found that the updated version containing a bug causing your website crashes. You understand this bug comes from other team, and still want to keep recent work from your team, so you decide just to revert some file(s), folder(s) to a specific version.
  • Solution: Remember the last working version (you can use svn info to view current revision, and remember it before using svn update). Use svn merge so that you can ”merge backwards” – apply a diff between the current and previous version to the current version (so you end up with a working copy looking like the old version):
    sh-4.1$ svn merge index.php -r 1789:1481
    --- Reverse-merging r1789 through r1482 into 'index.php':
    U    index.php

Switching code to a new branch/tag

  • Cause: your current version on production server is from the tag 1.0.0 (according to product version 1.0.0). After finishing developing for new features, you tagged the new version as 1.0.1, and want to change code on production from version 1.0.0 to 1.0.1.
  • Solution: Remember the last working version (you can use svn info to view current revision) before applying changes. In order to switch code to a new tag/branch with updates, we use svn sw  (so that we will change svn to new location (the same repository with the previous one), and upate code the latest version) as follows:
    sh-4.1$ svn switch http://yourdomain.com/root-repo/tags/1.0.1 .

Relocate a working repo

  • Cause: Your SVN server was moved to another domain / address / IP. In this case, we must relocate the current working repository to the new remote one.
  • Solution: Use switch with relocate option as follows:
    [bash]svn switch –relocate http://www.OLDwebsite.com/svn/REPO/trunk/path https://www.NEWwebsite.com/svn/REPO/trunk/path .[/bash]

Leave a comment

Your email address will not be published. Required fields are marked *