Version Control Software: Subversion

Dr. Lawlor, CS 202, CS, UAF

So in a big project, emailing software back and forth gets to be really unworkable: nobody knows what's the latest version, everybody's constantly emailing each other copies and partial updates, and there is no single working version.

There is a better way to share code, called version control.

The basic idea is to store the current version of the code on a server somewhere, and everbody can "check out" (co) a new clean copy, "update" their copy to have the latest changes, "check in" (ci) their changes, and "blame" changes on a particular version.

Here's a narrative example of how this usually goes:

Developer BILL
Developer TED
OK, first I need to set up my copy of the project.
BILL$ svn co http://www.cs.uaf.edu/2010/svn/202demo    
Checked out revision 0.

Hmm, looks like there aren't any files yet.  I'll make a file "test.cpp", and check it in.  Oops, I have to "add" it first, then check it in!

BILL/202demo$ notepad test.cpp
BILL/202demo$ svn ci test.cpp
svn: Commit failed (details follow):
svn: 'BILL/202demo/test.cpp' is not under version control
BILL/202demo$ svn add test.cpp
A test.cpp
BILL/202demo$ svn ci test.cpp
Adding test.cpp
Transmitting file data .
Committed revision 1.


I wonder what's happening with the project?  Better set up my copy:
TED/$ svn co http://www.cs.uaf.edu/2010/svn/202demo/     
A 202demo/test.cpp
Checked out revision 1.

Good--looks like Bill actually wrote a "test.cpp".  But it doesn't compile.  I'll fix it, then check in my copy:
TED/202demo$ svn ci test.cpp
Sending test.cpp
Transmitting file data .
Committed revision 2.
Nice!  Ted fixed my code.  I'll grab the updated version.
BILL/202demo$ svn update 
U test.cpp
Updated to revision 2.

Now I'll do some more work on the file, and check mine in.
BILL/202demo$ svn ci test.cpp
Sending test.cpp
Transmitting file data .
Committed revision 3.
I have some more work to do on that file.  I'll modify my copy, and check it in:

TED/202demo$ svn ci
Sending test.cpp
svn: Commit failed (details follow):
svn: File or directory 'test.cpp' is out of date; try updating
svn: resource out of date; try updating
svn: Your commit message was left in a temporary file

Oops!  I guess I need to update first, to get BILL's changes:
TED/202demo$ svn update
G test.cpp
Updated to revision 3.

Looks like subversion managed to integrate Bill's changes with mine.
I wonder what those changes were?
TED/202demo$ svn annotate test.cpp 
1 - #include <iostream>
1 -
1 - int main() {
3 - std::cout<<"Woa!\n";
2 - std::cout<<"Sup!\n";
1 - return 0;
1 - }


OK, that will work.  Now I'll check in my modified copy:

TED/202demo$ svn ci 
Sending test.cpp
Transmitting file data .
Committed revision 4.
OK, back to work.  Let's see if there are any changes.

BILL/202demo$ svn update
U test.cpp
Updated to revision 4.

Let me change that first line:

BILL/202demo$ svn ci
Sending test.cpp
Transmitting file data .
Committed revision 5.
Let me change that first line.

Now I'll do an update before checking in.
TED/202demo$ svn update
Conflict discovered in 'test.cpp'.
Select: (p) postpone, (df) diff-full, (e) edit,
(h) help for more options: df
--- .svn/text-base/test.cpp.svn-base Wed Apr 28 17:31:13 2010
+++ .svn/tmp/tempfile.3.tmp Wed Apr 28 17:31:52 2010
@@ -1,7 +1,11 @@
#include <iostream>

int main() {
- std::cout<<"Woa!\n";
+<<<<<<< .mine
+ std::cout<<"WWWWWWWoa!\n";
+=======
+ std::cout<<"DUUUDE. Woa!\n";
+>>>>>>> .r5
std::cout<<"Sup!\n";
std::cout<<"Man!\n";
return 0;
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
(h) help for more options: p
C test.cpp
Updated to revision 5.

Oops!  Bill changed the same line I did, so Subversion didn't know how to fix that.  I'll manually fix this conflict, and then check in normally.

Subversion commands:
Versions of Subversion:
I created a Subversion repository on the www.cs server for each of your projects--feel free to use this, or try out in the 202demo repository!