This document is not intended to be a full guide to using SVN effectively. It should, however, be a sufficient introduction for how you’ll be using it in CS 225 (and future CS/ECE courses).

Subversion in CS 225

Subversion will be used throughout this semester as the version control system for MPs and labs. Specifically, we will be using SVN for two functions:

• Distribution of provided code.

While we do not require that you learn and use good version control practices, we cannot stress enough how useful a good version control system can be when good practices are used. The following is a brief list of good version control practices:

• Always use a good commit message which describes the changes in the commit.
• Never check in broken code. (This is more important when working in groups, but still good practice.)
• Commit regularly and frequently. For example, commit when you’re done writing a function. This allows both simpler commit messages and greater confidence in the repository.

Again, the above practices are not hard and fast, nor complete, but they should help you complete your MPs and future coding projects should you use SVN for them as well.

The Commands

svn help

Syntax: svn help [SUBCOMMAND]

The help command displays the internal SVN help. svn help displays an overview of the available subcommands, and svn help SUBCOMMAND gives the help for a particular SUBCOMMAND.

Example

To get help on the add subcommand, run:

svn help add


svn checkout (svn co)

Syntax: svn checkout URL [directory]

The checkout command is used to download a copy of the repository located at URL. If directory is given, the repository is downloaded into that directory. By default, it is downloaded into a directory named after the last segment of URL.

Example

To checkout this semester’s repository into a directory named cs225, run:

svn checkout https://subversion.ews.illinois.edu/svn/fa17-cs225/NETID/ cs225


replacing NETID with your NetID.

svn update (svn up)

Syntax: svn update

The update command downloads the latest revisions from the repository. Use it to download newly released assignments or if you’ve committed on a different machine.

Example

To update your copy of the repository:

cd path/to/your/cs225/directory
svn update


svn add

Syntax: svn add FILE...

The add command tells SVN to start tracking a particular file or set of files.

Note that svn add does NOT upload files. You need to also svn commit it.

Example

To add a file named partners.txt, run:

svn add partners.txt


svn status (svn st)

Syntax: svn status

The status command displays what will be committed on the next svn commit. It outputs a list of files, each with a single-letter status indicator:

• A file.cpp means that file.cpp has been added and will be uploaded on with the next svn commit.
• M file.cpp means that file.cpp has been modified and the modifications will be uploaded with the next svn commit.
• D file.cpp means that file.cpp has been deleted and the file will be deleted with the next svn commit.
• ? file.cpp means that file.cpp is not going to be uploaded and will be ignored by Subversion.
• C file.cpp means that file.cpp is in conflict, which means that the version on the repository and your local copy have both changed. See Resolving Conflicts.

There are other status indicators not listed here; see svn help status for the full list.

Example

To get the status of files in the current directory, run:

svn status


This may give something like

A       main.cpp
M       rgbapixel.cpp
?       rgbapixel.h


which means:

• main.cpp is a new file that is going to be committed.
• modifications to rgbapixel.cpp are going to be committed.
• rgbapixel.h is not being tracked by Subversion.

svn commit (svn ci)

Syntax: svn commit -m "COMMIT_MESSAGE"

The commit command is used to upload changes to the repository. A commit message must be given. See this StackOverflow question for guidelines on how to write good commit messages.

svn commit will display the revision number created at the end of the commit. If Subversion prints out errors or it doesn’t say Committed revision REVISION_NUMBER., your commit didn’t happen.

Example

svn commit -m "Finish main.cpp; fix a bug in rgbapixel.cpp"


which may output something like

Adding         main.cpp
Sending        rgbapixel.cpp
Transmitting file data ...
Committed revision 400.


which means:

• main.cpp, rgbapixel.cpp, rgbapixel.h were uploaded
• The revision created was number 400.

svn log

Syntax: svn log PATH

The log command is used to view the history of a given file (or directory). PATH can be either a local file or a URL. (To view the log for the current directory, use svn log .)

svn log can produce a lot of output; it’s usually best to pipe it to a pager like less:

svn log . | less


In less, use Vim keys (or the arrow keys) to navigate. Press q to quit.

Example

To view the log for the current directory, run:

svn log .


which may output something like

------------------------------------------------------------------------
r400 | netid | 2015-08-20 16:14:55 -0500 (Thu, 20 Aug 2015) | 1 line

Finish main.cpp; fix a bug in rgbapixel.cpp
------------------------------------------------------------------------
r394 | netid | 2015-08-20 15:58:03 -0500 (Thu, 20 Aug 2015) | 1 line

Implement the RGBAPixel class
------------------------------------------------------------------------
r100 | tolar2 | 2015-08-18 00:08:39 -0500 (Tue, 18 Aug 2015) | 1 line

releasing mp1
------------------------------------------------------------------------


Note that the commit messages are displayed, as well as the revision numbers, the author of the commit, and the date of the commit.

Fixing SVN

SVN can oftentimes get into a weird state, whether that be to conflicts or other reasons.

There are usually “correct” ways to solve SVN problems, but the safest and easiest is to just re-checkout your repository:

# Move your old cs225/ directory out of the way
mv -Tn cs225 cs225.old


If the mv command gives an error, that means that you’ve likely already done this at some time in the past. Either delete cs225.old (after checking that you don’t need anything in it), or pick a different name (e.g., cs225.old1).