Versioning with Subversion
From KdjWiki
Contents |
Overview
Changes to files can be stored with subversion. This improves over other backup strategies by allowing you to rollback to any previous version. Changes are stored as differences to the previous version and as such the space used is significantly less than it would be if you stored complete copies of files everytime they changed. Versions can be labeled and rolling back can be specified to these versions or particular dates.
Command Summary
svn checkout svn import svn add svn delete
Create Repository
Initial import
Use the checkout action to link a folder to a repository:
$ svn checkout http://svn.domainname.com/repo /path/to/source
Add current files:
$ cd /path/to/source $ svn add *
Commit to repository:
$ cd /path/to/source $ svn commit -m "Initial Import"
Verify import:
$ svn status /path/to/source
Daily update
#!/bin/bash
source="/path/to/source"
cd "${source}"
need=`svn status`
if [ "$need" != "" ]; then
# don't worry about modified or deleted files
need=`echo "${need}" | grep -v "^M" | $grep -v "^D"`
if [ "$need" != "" ]; then
added=`echo "${need}" | grep -F "?"`
if [ "${added}" != "" ]; then
ret=`svn add -q * > /dev/null 2&>1`
fi
need=`svn status | grep -v "^M" | grep -v "^A"`
if [ "$need" != "" ]; then
gone=`echo "${need}" | grep -F "!"`
echo
if [ "${gone}" != "" ]; then
echo "You have removed file(s) from ${source} and will need to address with: svn delete {filename}"
else
echo "You have made changes to ${source} that require manual intervention - please address"
fi
echo "${need}" | grep -v "^M" | grep -v "^A"
echo
fi
fi
today=`date`
ret=`svn commit -m "Update - ${today}"`
fi
exit 0
Rolling Back
To see the version are available for a specific file:
$ svn log {filename}
To see the differences between the current version and a specific version, you can use:
$ svn diff -r {revision #} {filename}
To compare two revisions, you can use:
$ svn diff -r {revision1 #}:{revision2 #} {filename}
To retrieve a specific version:
$ svn cat -r {revision #} {filename}
And you can redirect this to a file such as:
$ svn cat -r {revision #} {filename} > {new filename}
Or you could checkout a specific version of the whole project:
$ svn checkout -r {revision #}