Course notes taken for CSCB07/CSC207 at UofT (Software Design).

Basic introduction to version control and how to use SVN.

Overview

Why not email code to each other?

  • Someone is responsible for merging different source files together into one, which is painful.
  • No way to track what file got changed what time by which developer.

What is version control?

Version control tracks files over a period of time (who wrote what and what your file looked like an hour ago etc.). It also automatically merges contributions.

It creates revisions, which keep track of the changing states of files over time and merge contributions of multiple developers.

Benifits of Version Control

  • Data integrity
    • Nothing is every deleted or lost.
  • Productivity
    • Automatically integrates work from different developers into a central repository.
    • If a revision introduces errors, you can easily go back to a previous version.
  • Accountability
    • Can track who wrote which part of the code.
    • Track when the change is added.
    • Track subsequent changes made by other developers.
  • Record Keeping
  • Rapid Development
  • Git

Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. Its current maintainer since 2005 is Junio Hamano.

As with most other distributed version-control systems, and unlike most client–server systems, every Git directory on every computer is a full-fledged repository with complete history and full version-tracking abilities, independent of network access or a central server. (Wikipedia)

  • Perforce

Enterprise version control, seems like it is used by gaming companies.

  • Microsoft Visual SourceSafe

Targets towards small teams, this software is not supported by Microsoft anymore.

  • Subversion (SVN)

Quite widely used, built by Apache Foundation.

Client-Server Architecture

SVN uses client-server architecture. This architecture is very common among many programs.

Note Git is not client-server, it does not have a centralized server at all.

SVN client server

Use Subversion

Before doing anything, you must first checkout the repository:

svn checkout https://lecture1207.googlecode.com/svn/trunk/ lecture1207 --username [email protected]

Above command will checkout repository https://lecture1207.googlecode.com/svn/trunk/ to a folder called lecture1207 as user [email protected].

After creating a new file, you must add it to SVN tracking tree:

touch newfile.txt
svn add newfile.txt

Then you can commit using the following command:

svn commit -m "Add newfile.txt" newfile.txt

To fetch updates from server, use the command:

svn update

svn status

svn status command is used to check current repository status, it will give you the following output:

STATUS_CODE file_name1
...

STATUS_CODE can be one of the following:

  • - Nothing has changed.
  • A - Marked for addition.
  • D - Marked for deletion.
  • M - Item modified.
  • R - Item replaced (was removed, but then a new file with same name is added).
  • C - Contents of the file conflicts with the update from repository.
  • X - Item is present because of an externals definition.
  • I - Ignored by svn:ignore.
  • ? - Not under version control.
  • ! - Item is missing from working copy.
  • ~ - Was version as one kind of object (for example file), but then replaced with another type (for example directory).

svn log

svn log [PATH]

svn log URL[@REV] [PATH...]

Shows log messages from the repository. If no arguments are supplied, svn log shows the log messages for all files and directories inside (and including) the current working directory of your working copy. You can refine the results by specifying a path, one or more revisions, or any combination of the two. The default revision range for a local path is BASE:1.

Resolve Conflicts

Following are the instructions provided by the instructor, however it is outdated.

To discard my own change:

svn revert

To discard other person’s change:

cp someFile.mine.java someFile.java
svn resolved
svn commit -m “I accepted mine changes”

However, there is a new instruction: http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.resolve.html