Software Carpentry
Version Control



You Can Skip This Lecture If...

Problem #1: Collaboration

Solution: Version Control

Problem #2: Undoing Changes

Solution: Version Control (Again)

Which Version Control System?

Basic Use

How To Do It

Resolving Conflicts

Example of Resolving

Example of Resolving (continued)

Example of Resolving (continued)


Binary Files


Rolling Back

Creating and Checking Out

Subversion Command Reference

Reading Subversion Output



Exercise 4.1:

Check out a copy of the Subversion repository you'll be using in this course: svn co https://svn/public/sc $HOME/course You will submit all of your exercises in this course by checking files into your repository. For that to work, you need to create your personal tree into the common repository: cd $HOME/course/; mkdir yourname

You can browse the content of the repository pointing your browser to: https://svn/public/sc/

Exercise 4.2:

Create a file course/yourname/20071114/README (where course/yourname is the root of your working copy of the Subversion repository), and write your name, you email address, your telephone number, your credit card number, your bank account data, and everything else your instructor may need to steal your identity. Commit this file to the repository. Remember to provide a meaningful comment when committing the file!

Exercise 4.3:

What's the difference between mv and svn mv? Put the answer in a file called course/yourname/20071114/mv.txt and commit your changes.

Once you have committed your changes, type svn log in your course/yourname directory. If you didn't know what you'd just done, would you be able to figure it out from the log messages? If not, why not?

Exercise 4.4:

In this exercise, you'll simulate the actions of two people editing a single file. To do that, you'll need to check out a second copy of your repository. One way to do this is to use a separate computer (e.g., your laptop, your home computer, or a machine in the lab). Another is to make a temporary directory, and check out a second copy of your repository there. Please make sure that the second copy isn't inside the first, or vice versa—Subversion will become very confused.

Let's call the two working copies Blue and Green. Do the following:

a) Create Blue/20071114/planets.txt, and add the following lines:

Download exer_merge_01.txt

1 Mercury 2 Venus 3 Earth 4 Mars 5 Jupiter 6 Saturn

Commit the file.

b) Update the Green repository. (You should get a copy of planets.txt.)

c) Change Blue/20071114/planets.txt so that it reads:

Download exer_merge_02.txt

1 1. Mercury 2 2. Venus 3 3. Earth 4 4. Mars 5 5. Jupiter 6 6. Saturn

Commit the changes.

d) Edit Green/20071114/planets.txt so that its contents are as shown below. Do not do svn update before editing this file, as that will spoil the exercise.

Download exer_merge_03.txt

1 Mercury 0 2 Venus 0 3 Earth 1 4 Mars 2 5 Jupiter 16 (and counting) 6 Saturn 14 (and counting)

e) Now, in Green, do svn update. Subversion should tell you that there are conflicts in planets.txt. Resolve the conflicts so that the file contains:

Download exer_merge_04.txt

1 1. Mercury 0 2 2. Venus 0 3 3. Earth 1 4 4. Mars 2 5 5. Jupiter 16 6 6. Saturn 14

Commit the changes.

f) Update the Blue repository, and check that planets.txt now has the same content as it has in the Green repository.

Exercise 4.5:

Add another line or two to course/yourname/20071114/README and commit those changes. Then, use svn merge to restore the original contents of the file (course/yourname/20071114/README), and commit the result. When you are done, README should look the way it did at the end of the first part of the previous exercise.) Note: the purpose of this exercise is to teach you how to go back in time to get old versions of files—while it would be simpler in this case just to edit README, you can't (reliably) do that when you've made larger changes, to multiple files, over a longer period of time.

Exercise 4.6:

Subversion allows users to set properties on files and directories using svn propset, and to inspect their values using svn propget. Describe three properties you might want to change on a file or directory, and how you might use them in your current project.