Introduction to Subversion:
a Version Control System
2012/05/19 Che-Hsien Chou
About Homework #4
Goal: Learn how to use a version control system to maintain software projects.
Detail:
You should study the concept of version control system, and its server-client model.
A hands-on test will be used to test your
knowledge of using Subversion to manipulate different versions of a Visual Studio project workspace.
What is Subversion?
A free open-source version control system.
Manage files and directories, and the changes made to them, over time.
Home Page: http://subversion.tigris.org
The original subversion project does not provide GUI.
TortoiseSVN(1/2)
A Windows GUI version of Subversion.
We will use TortoiseSVN in the fllowing.
Download and install TortoiseSVN at http://tortoisesvn.tigris.org
If successfully installed, right-click anywhere in the explorer will show the svn options.
TortoiseSVN(2/2)
Subversion System Architecture
Subversion server
repository
Client A
Client B
Client C
Project Local Working Copy
Local Working Copy
Local Working Copy
sort.c
search.c
retrieve.c
updated
Subversion’s Features
Directory versioning
Track changes to the whole directory trees over time.
True version history
Add, delete, copy, and rename both files and directories.
Atomic commits
A collection of modifications either goes into the repository completely, or not at all.
Versioned metadata
Each file and directory has a set of properties—keys and values associated with it.
Consistent data handling
Identically for both text and binary files.
The Problem of File-Sharing
The Lock-Modify-Unlock Solution
Only one person changes a file at a time.
Administrative problems.
Unnecessary serialization.
A false sense of security.
The Copy-Modify-Merge Solution (Subversion)
Each user’s client contacts the project repository and creates a personal working copy.
Users then work simultaneously and independently, modifying their private copies.
Finally, the private copies are merged into a new, final version.
Fundamental Concepts of Subversion
The Repository
Working Copies
Revisions
The Repository
A central store of data.
Store information in the form of a filesystem
tree—a typical hierarchy of files and directories.
Remember every change ever written to it.
Track changes to data over time.
/
Calc
Paint
Makefile
Button.c Integer.c
Makefile
Brush.c Canvas.c
Repository: Basics
Subversion uses URLs to identify versioned files and directories in Subversion repositories.
“One repository, one project” or “one repository, multiple projects”
Please refer to Chapter 6 of the book “Version Control with Subversion” for understanding of advanced Subversion server options
†.
To practice, we use local directory to create a repository in the following.
† http://svnbook.red-bean.com/index.en.html
Repository: Create
To create a new repository, we first create a new directory. eg. C:\repos
Right-click the new directory C:\repos and press
“Create repository here.”
Now C:\repos is a new empty repository.
Repository: Repository Browser
We can use the repository browser provided by
TortoiseSVN to browse all projects in a repository.
To connect to a repository
Google svnserve server
http://nctu-20012-spring-ics.googlecode.com/svn/trunk/ nctu- 20012-spring-ics-read-only
Local repositroy
file:///C:/repos
Repository: Create Folder
As an example, we first create three folder in the repository.
Right-clicking the repository directory in the repository browser show all functions we need to create, add, delete, and import files.
We now create trunk, branch, and tag folders.
Note that “add folder” and “add file” adds existing files and folders into the repository. In other hand, “create folder”
creates empty folder in the repository.
Repository: Import and Add
Let’s assume we have an existing project “CS demo” including some source codes, now we try to add this project into the
repository and put it in the trunk folder. This can be done using either “import” or “add”.
Import : copy an unversioned tree of files into a repository
Right-click the “CS demo” folder in your explorer and press import
Select the trunk folder by pressing the button “…”
Press “OK”, the importing results will be shown when all operations are done.
Add file and add folder: add files, directories, or symbolic links
Open the repository browser.
Right-click the trunk folder and press “Add file” or “Add folder”
Select file or folder we want to import.
Import (1/4)
Import (2/4)
Import (3/4)
Import (4/4)
Add File (1/2)
Add File (2/2)
Working Copies
Come out of the repository.
An ordinary directory tree on your local system.
Your own working copy is your own private work area.
Subversion will never incorporate other people’s changes, nor make your own changes available to others, until you explicitly tell it to do so.
The working administrative directory (.svn) includes information which helps Subversion recognize
which files contain unpublished changes, and which files are out-of-date with respect to other’s work.
Revisions
An svn commit operation publishes changes to any number of files and directories as a single atomic transaction.
Each time the repository accepts a commit, this creates a new state of the filesystem tree, called a revision.
Each revision is assigned a unique natural number.
Subversion’s revision numbers apply to entire trees, not individual files.
Checkout a Working Copy
Create a private working copy from remote repository.
The repository browser also provide the checkout function.
You can save the local working copy in any directory on your own computer.
When checking out, you can choose any revision.
HEAD revision: the latest revision in the repository.
The “Show log” button shows the revision history and help us to find the revision we want.
Checkout (1/4)
Checkout (2/4)
Checkout (3/4):Show Log
Checkout (4/4):Complete
Make Changes
Now we can modify the source code in out own local working copy.
A modified file has a “!” on it.
Change to your working copy directory
If we add any new file in the working copy, there will be a “?” on it.
To add the new file when committing, right-click this file and mark the file as added (a “+” sign
will be shown) by selecting “add”.
Update Your Working Copy
You can update to the latest version anytime by
right-clicking the project folder and pressing “SVN update”.
Note that you can also update your working copy to any revision.
You can also update to an older version by “update to revision.”
To prevent any error, we should update our local working copy before committing.
Update
Conflict
Why Conflict?
repos
CS demo CS demo1
1.Checkout to CS demo
repos
CS demo CS demo1
2.Checkout to CS demo1
Abc…
Abc…
Abc…
Abc… Abc…
repos
CS demo CS demo1
3.Make changes and Commit
Ade…
Abc… Ade…
repos
CS demo CS demo1
4.Make other changes and Update
Ade…
Acc… Ade…
Conflict
Merge Others’ Changes
After “svn update”, you cannot commit if you get a conflict
A conflict means that others already commit some changes on files which you just modified.
Deal with a conflict
Merge the conflicted text “by hand”.
Copy one of the temporary files on top of your working file.
Run svn revert filename to throw away all of your local changes.
TortoiseMerge
TortoiseMerge is a tool helping us to resolve the conflict
Right-click the conflict file and select “Edit Conflicts”
Check the difference between yours and the new version.
The upper toolbar provides some solutions to resolve the conflict. We can also modify the file by typing in the
“merged” window.
Note that “diff” and “diff with previous version” functions are also useful to track the difference between versions
Edit Conflicts
Tortoise Merge
Merging conflicts by hand
Open the source file via any editor
Commit your changes
After resolving all conflicts, now
we can commit the modified files.
Commit (1/2)
Commit (2/2)
Branching, tagging, and merging
/
trunk
tags
nweb.c client.c
Realease-1.0 Release-1.2
branches
John Mary
Branching, tagging, and merging
Trunk: the main line of development is going to take place.
Branch: a line of development that exists
independently of another line, yet still shares a
common history if you look far enough back in time.
Branching and Tagging
To create a branch or a tag, select “Branch/tag”
option.
You can specify a
revision to create the
new branch/tag.
Create a New Branch
Switching
After successfully creating a new branch/tag, any local changes will still commit to the original
position (trunk).
To work on a specific branch, we should first switch to the branch.
Now the further changes will be committed to the branch.
Switch (1/2)
Switch (2/2)
Revision Graph (1/2)
The revision graph shows the revision tree, which presents the version history.
The number represents revision, all
branches/tags will be shown and we can
easily see which revision a branch/tag is
created from.
Revision Graph (2/2)
Update To An Old Version
If we want to revert to an older version in the repository, select “update to revision…”
If you are not sure which revision to use, “show log” may help. You can find what changes have done and some
comments there.
Note that another function called “Revert” let us revert to pre-modified version in our local records.
Update To Revision
Log Manager
Update to a specific revision
Recommended Reading
http://www.cs.ubc.ca/~vailen/svn_howto.htm