SVN by Example

The example setup

The following test repository was created and used in the following examples.

1
2
3
4
$ cd /tmp
$ svnadmin create `pwd`/testrepo
$ svn mkdir -m "Added trunk" file:///tmp/testrepo/trunk/
$ svn co file:///tmp/testrepo/trunk/ testwc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$ echo "Added file in revision 2" > testfile.txt
$ svn add testfile.txt
$ svn ci -m "Rev 2" 
Sending        testfile.txt
Transmitting file data .
Committed revision 2.
$ echo "Added a new line in rev 3" >> testfile.txt
$ svn ci -m "Rev 3" 
Sending        testfile.txt
Transmitting file data .
Committed revision 3.
$ echo "Added yet another line in rev 4" >> testfile.txt
$ svn ci -m "Rev 4" 
Sending        testfile.txt
Transmitting file data .
Committed revision 4.

Rollback with subversion

To me a rollback is when you want to undo one or more commited changes. Subversion does not let you delete repository revisions so instead you need to appened a new revision at the end of the trunk/branch.

This can be achieved by manually editing all files (removing any files/directories that might have been added) and then check in the result. Another and quicker way to do it is to do a “reversed merge”, that is to merge the newer (faulty) version with the older.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$ svn merge -r 4:2 .
U testfile.txt
$ svn ci -m "Rollbacked to revision 2"
Sending        testfile.txt
Transmitting file data .
Committed revision 5.
$ svn diff file:///tmp/testrepo/trunk/@2 file:///tmp/testrepo/trunk/@5
$ svn diff file:///tmp/testrepo/trunk/@4 file:///tmp/testrepo/trunk/@5 
Index: testfile.txt
===================================================================
--- testfile.txt        (revision 4)
+++ testfile.txt        (revision 5)
@@ -1,3 +1 @@
 Added file in revision 2
-Added a new line in rev 3
-Added yet another line in rev 4

Updated third party software imported into your subversion repository

When you version control a third party software it is sometimes necessary to upgrade this to a later release.

Since you often only get a tar file containing the new release it might not be trivial to find out which files that was changed, new or even deleted compared to the old release. A simple way to do it is just to unpack the new release into your workspace and ‘‘svn status’’ will tell you which files are new or changed. But what about the deleted/obsolete files ?

Step 1: Remove all files from your workspace

Remove all files but keep the .svn directories using the following command.

1
find . -type f -a -not -path '*.svn*' -exec rm -f {} \;

Step 2: Unpack the new release

1
tar xvzf /tmp/new_release.tar.gz

Step 3: Find out which files that have been deleted

First list any files that has been removed in this release of the software.

1
svn status | grep "! "

Look through the list, there might be some files that you’ve added to the repository that is not part of the third party vendors release. If so use ‘‘svn revert’’ to recreate them.

When your happy with the result remove the remaining deleted files from version control.

1
svn status | grep "! " | awk '{print $2;}' | xargs svn rm

Step 4: Add any new files

Add any new files that isn’t under version control already.

1
svn status | grep "? " | awk '{print $2;}' | xargs svn add

Step 5: Verify and check in

Verify that the new release builds and/or works as expected and check in.