Version Control

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

This text looks at different forms of version control.


Contents

[edit] The Basic Tools of Version Control

[edit] What is Version Control?

The following quote from wikipedia defines version control:

Revision control (also known as version control (system) (VCS), source control or (source) code management (SCM)) is the management of multiple revisions of the same unit of information. It is most commonly used in engineering and software development to manage ongoing development of digital documents like application source code, art resources such as blueprintss or electronic models, and other projects that may be worked on by a team of people. Changes to these documents are usually identified by incrementing an associated number or letter code, termed the "revision number", "revision level", or simply "revision" and associated historically with the person making the change. A simple form of revision control, for example, has the initial issue of a drawing assigned the revision number "1". When the first change is made, the revision number is incremented to "2" and so on.

In this text the term Version Control will be used.

[edit] An Example

This section will build up a simple example to illustrate some of the key concepts of version control.

Assume that we're running a restaurant and we want to print a menu. On the first day of business we have the following menu in a file menu.txt.

[Date]
Monday 5th January 2009

[Starters]
Starter of the day.

[Main]
Dish of the day.

----
FILE: menu.txt

The next day we add some additional items.

[Date]
Tuseday 6th January 2009

[Starters]
Starter of the day.
Chicken Soup

[Main]
Dish of the day.
Mushroom Ommelette

----
FILE: menu.txt

In our file we now only have a record of the last menu we used. If we haven't kept any printed copies of the menu we will have lost the record for Monday 5th January 2009. We could avoid this by keeping each menu in a separate file.

[Date]
Monday 5th January 2009

[Starters]
Starter of the day.

[Main]
Dish of the day.

----
FILE: menu-20090105.txt
[Date]
Tuseday 6th January 2009

[Starters]
Starter of the day.
Chicken Soup

[Main]
Dish of the day.
Mushroom Ommelette

----
FILE: menu-20090106.txt

TODO: note on file names.

[edit] Types of Version Control

  • Centralized
  • Distributed

[edit] Outline of Examples

  • Scenario 1: Single User Version Control of a Single File
  • Scenario 2: Single User Version Control of Multiple Files
  • Scenario 3: Single User Version Control of Multiple Files and Branches
  • Scenario 4: Multiple Users Version Control of Multiple Files
  • Scenario 5: Multiple Users Version Control of Multiple Files and Branches
  • Scenario 6: Multiple Users Using Centralized Version Control
  • Scenario 7: Multiple Users Using Distributed Version Control

[edit] Scenario 1: Single User Version Control of a Single File

This scenario will introduce the basic concepts of version control. It is mainly intended for people with no experience of version control. It will cover the concepts of diffs (differences), patches, merging, revisions of an item and some of the subtleties of using version control effectively.

  • Example uses a restaurant menu.
  • Use GNU Diff Utils initially.
  • Keep 7 days of menus.
  • Create a patch between each day.
  • Apply the patches forwards and backwards.
  • Keep latest menu and reverse patches only.
  • Compare sizes.
[Date]
Monday 5th January 2009
 
[Starters]
Starter of the day.
 
[Main]
Dish of the day.
 
[Desserts]
Creme Brulee
[Date]
Tuseday 6th January 2009
 
[Starters]
Starter of the day.
Chicken Soup
 
[Main]
Dish of the day.
 
[Desserts]
Ice Cream
[Date]
Wednesday 7th January 2009
 
[Starters]
Starter of the day.
 
[Main]
Dish of the day.
 
[Desserts]
Creme Brulee
[Date]
Thursday 8th January 2009
 
[Starters]
Chicken Soup
Starter of the day.
 
[Main]
Dish of the day.
 
[Desserts]
Ice Cream
menu-20090105.txt menu-20090106.txt menu-20090107.txt menu-20090108.txt
[Date]
Friday 9th January 2009
 
[Starters]
Starter of the day.
 
[Main]
Dish of the day.
Fish and Chips
 
[Desserts]
Apple Pie
[Date]
Saturday 10th January 2009
 
[Starters]
Starter of the day.
Chicken Soup
 
[Main]
Dish of the day.
[Date]
Sunday 11th January 2009
 
[Starters]
Starter of the day.
Prawn Cocktail
 
[Main]
Roast Lunch
 
[Desserts]
Ice Cream
Apple Pie
Cheese and Biscuits
menu-20090109.txt menu-20090110.txt menu-20090111.txt

[edit] GNU diffutils

The "GNU diffutils" package is a complete set of programs for handling differences between groups of files and merging files. The GNU diffutils package contains the following utilities:

  • diff - shows the difference between two files
  • cmp compares binary files
  • sdiff merges two files interactively
  • diff3 shows the differences amaong three files
  • patch applies differecnes to existing files

[edit] Using diff (ubuntu)

[edit] Using diff (Windows XP)

We will start by looking at the differrences between the menu on Monday and the Menu on Tuesday.

~Menus>diff menu-20090105.txt menu-20090106.txt
2c2
< Monday 5th January 2009
---
> Tuesday 6th January 2009
5a6
> Chicken Soup
11c12
< Creme Brulee
---
> Ice Cream
 
~Menus>

The diff shows that there have been three changes, 2c2, 5a6 and 11c12. The summary of a changed is shown in the form <number><alpha><number>.

~Menus>diff menu-20090106.txt menu-20090107.txt
2c2
< Tuesday 6th January 2009
---
> Wednesday 7th January 2009
6d5
< Chicken Soup
12c11
< Ice Cream
---
> Creme Brulee
 
~Menus>

[edit] Scenario 2: Single User Version Control of Multiple Files

[edit] White Noise

White noise in version control is where changes are made to files under version control that show up as changes but do not change the "semantics" of the file. White noise is most common when white space is "reorganised" for example when tabs are replaced by spaces. White noise is a problem since it often necessitates having to review diffs on files that haven't really changed.

[edit] Scenario 3: Single User Version Control of Multiple Files and Branches

[edit] Scenario 4: Multiple Users Version Control of Multiple Files

[edit] Scenario 5: Multiple Users Version Control of Multiple Files and Branches

[edit] Scenario 6: Multiple Users Using Centralized Version Control

[edit] Scenario 7: Multiple Users Using Distributed Version Control

[edit] Subversion

The design of Subversion is based on CVS:

Subversion was originally designed to be a better CVS, so it has most of CVS's features. Generally, Subversion's interface to a particular feature is similar to CVS's, except where there's a compelling reason to do otherwise.

Subversion has since expanded beyond its original goal of replacing CVS, but its history influenced its feature and interface choices; Subversion today should still feel very familiar to CVS users.


[edit] Subversion Walk Throughs : Windows XP

[edit] Walk Through: Installing Subversion and Subversion Tools

  • Download the msi svn-1.4.6-setup.exe
  • Run the msi

Subversion is made up of several components. Here we'll check the installation of the three components:

  • svn
  • svnadmin
  • svnlook
  • Open a command prompt.
C:\>svn --version
svn, version 1.4.5 (r25188)
   compiled Aug 22 2007, 20:49:04
 
Copyright (C) 2000-2006 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
 
The following repository access (RA) modules are available:
 
* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
  - handles 'http' scheme
  - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme



C:\>svnadmin --version
svnadmin, version 1.4.5 (r25188)
   compiled Aug 22 2007, 20:49:04
 
Copyright (C) 2000-2006 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
 
The following repository back-end (FS) modules are available:
 
* fs_base : Module for working with a Berkeley DB repository.
* fs_fs : Module for working with a plain file (FSFS) repository.
C:\>svnlook --version
svnlook, version 1.4.5 (r25188)
   compiled Aug 22 2007, 20:49:04
 
Copyright (C) 2000-2006 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
 
The following repository back-end (FS) modules are available:
 
* fs_base : Module for working with a Berkeley DB repository.
* fs_fs : Module for working with a plain file (FSFS) repository.
 
C:\>

[edit] Walk Through: Setting Up a Repository

The svnadmin create command is used to create a repository. To make the distiniction clear between client or server in this example we will create two directories server and client. Administration of repositories in the examples is carried out in the server directory whilst client side work is carried out in the client directory.

[edit] svnadmin create repos

This section looks at creating a repository. In the day to day use of subversion this is a task you will only carry out infreqequently. For trying out new ideas it is useful to know how to set up a simple repository. To create a repository you need to use the svnadmin command.

C:\>svnadmin help create
create: usage: svnadmin create REPOS_PATH
 
Create a new, empty repository at REPOS_PATH.
 
Valid options:
  --bdb-txn-nosync         : disable fsync at transaction commit [Berkeley DB]
  --bdb-log-keep           : disable automatic log file removal [Berkeley DB]
  --config-dir arg         : read user configuration files from directory ARG
  --fs-type arg            : type of repository: 'fsfs' (default) or 'bdb'
  --pre-1.4-compatible     : use format compatible with Subversion versions
                             earlier than 1.4

Start by creating the server directory and change into this directory.

C:\WB>MD server
 
C:\WB>CD server

Create a repository in the repos directory.

C:\WB\server>svnadmin create repos
 
C:\WB\server>

We can now look at the standard directry sructure for a repository.

C:\WB\server>DIR repos
 Volume in drive C is MyCDrive
 Volume Serial Number is 64A5-9C22
 
 Directory of C:\WB\server\repos
 
09/01/2009  14:27    <DIR>          .
09/01/2009  14:27    <DIR>          ..
09/01/2009  14:27    <DIR>          conf
09/01/2009  14:27    <DIR>          dav
09/01/2009  14:27    <DIR>          db
09/01/2009  14:27                 2 format
09/01/2009  14:27    <DIR>          hooks
09/01/2009  14:27    <DIR>          locks
09/01/2009  14:27               234 README.txt
               2 File(s)            236 bytes
               7 Dir(s)  146,102,767,616 bytes free
C:\WB\server>
[edit] svnlook

svnlook is part of the subversion utilities. It provides a way of looking at a repository without changing anything about the repository.

C:\WB>svnlook youngest server\repos
0
 
C:\WB>

This shows that the repository is at revision 0, i.e. no commits have happened yet.

[edit] Adding Files to a Subversion Repository

If you have an existing file system that you want to add to version control there are several ways of doing this.

  • Use svn import
  • Create a versioned directory and then commit this.
[edit] svn import

svn import can be used to import an unversioned directory into subversion. The directory remains unversioned following the import. To work on a versioned copy of the directory it needs to be checked out from the repository.

C:\WB>svn help import
import: Commit an unversioned file or tree into the repository.
usage: import [PATH] URL
 
  Recursively commit a copy of PATH to URL.
  If PATH is omitted '.' is assumed.
  Parent directories are created as necessary in the repository.
  If PATH is a directory, the contents of the directory are added
  directly under URL.
 
Valid options:
  -q [--quiet]             : print as little as possible
  -N [--non-recursive]     : operate on single directory only
  --auto-props             : enable automatic properties
  --no-auto-props          : disable automatic properties
  -m [--message] arg       : specify log message ARG
  -F [--file] arg          : read log message from file ARG
  --force-log              : force validity of log message source
  --editor-cmd arg         : use ARG as external editor
  --encoding arg           : treat value as being in charset encoding ARG
  --no-ignore              : disregard default and svn:ignore property ignores
  --username arg           : specify a username ARG
  --password arg           : specify a password ARG
  --no-auth-cache          : do not cache authentication tokens
  --non-interactive        : do no interactive prompting
  --config-dir arg         : read user configuration files from directory ARG

A standard way of setting a up a project in subversion is to use the following structure:

project
   +--- branches
   +--- tags
   +--- trunk

We'll follow this structure here. First we create a temporary directory to import.

C:\WB>MKDIR temp
 
C:\WB>cd temp
 
C:\WB\temp>MKDIR branches tags trunk
 
C:\WB\temp>cd ..

We now import this structure into the repository. It is good practice to supply a message with each change to the repositiry using the -m option. In many repositories the need to supply a commit message is enforced by the server.

C:\WB>svn import temp file:///C:/WB/server/repos/ -m "Initial set up."
Adding         temp\trunk
Adding         temp\branches
Adding         temp\tags
 
Committed revision 1.
 
C:\WB>

We won't be using svnlook much during these walk throughs but the following shows the use of the svnlook youngest command. This is a server side command.

C:\WB>svnlook youngest server\repos
1
 
C:\WB>

Now that we've imported the temp directory we delete it.

C:\WB>RMDIR /S temp
temp, Are you sure (Y/N)? y
 
C:\WB>


[edit] Client Side

We will now check out the trunk from the repository and start working on this.

C:\WB\server>CD ..
 
C:\WB>MD client
 
C:\WB>CD client
 
C:\WB\client>

You can now check out the trunk from the repsitory into yur client working area.

C:\WB>svn co file:///C:/WB/server/repos/trunk client\trunk
Checked out revision 1.
 
C:\WB>
C:\WB>cd client
 
C:\WB\client>
C:\WB\client>DIR /A trunk
 Volume in drive C is PROGRAMS
 Volume Serial Number is 64A5-9C22
 
 Directory of C:\WB\client\trunk
 
23/02/2009  10:12    <DIR>          .
23/02/2009  10:12    <DIR>          ..
23/02/2009  10:12    <DIR>          .svn
               0 File(s)              0 bytes
               3 Dir(s)  145,724,104,704 bytes free
 
C:\WB\client>

It can be seen that there is a .svn directory in the trunk directory.

Next we move into the client trink directory. Look at the status of the directory and then look at a more detailed status of the directory.

C:\WB\client>CD trunk
 
C:\WB\client\trunk>svn status
 
C:\WB\client\trunk>svn status -v
                1        1 CozensJ      .

You can find out where the directory is versioned using the svn info command.

C:\WB\client\trunk>svn info
Path: .
URL: file:///C:/WB/server/repos/trunk
Repository Root: file:///C:/WB/server/repos
Repository UUID: 81664a5f-b906-8c41-a38a-d61973a1aa89
Revision: 1
Node Kind: directory
Schedule: normal
Last Changed Author: CozensJ
Last Changed Rev: 1
Last Changed Date: 2009-02-23 09:46:43 +0000 (Mon, 23 Feb 2009)

We now continue with the menu example. Open notepade and create a file "menu.txt".

C:\WB\client\trunk>notepad menu.txt

Checking the status now shows that the menu.txt is an unknown file to subversion.

C:\WB\client\trunk>svn status
?      menu.txt
 
C:\WB\client\trunk>svn add menu.txt
A         menu.txt
 
C:\WB\client\trunk>svn status
A      menu.txt
 
C:\WB\client\trunk>svn staus -v
Unknown command: 'staus'
Type 'svn help' for usage.
 
C:\WB\client\trunk>svn status -v
                1        1 CozensJ      .
A               0       ?   ?           menu.txt
 
C:\WB\client\trunk>svn diff
Index: menu.txt
===================================================================
 
C:\WB\client\trunk>svn diff
Index: menu.txt
===================================================================
--- menu.txt    (revision 0)
+++ menu.txt    (revision 0)
@@ -0,0 +1,11 @@
+[Date]
+Monday 5th January 2009
+
+[Starters]
+Starter of the day.
+
+[Main]
+Dish of the day.
+
+[Desserts]
+Creme Brulee
 
C:\WB\client\trunk>

[edit] Walk Through: Setting Up Subversion and TortoiseSVN

This walk through will show you how to set up subversion as a set of command line applications and also how to set up the TortoiseSVN client.

[edit] Walk Through: Multiple Workers and Conflicts

This walk through will walk you through a single user and then two users using a repository. It will show you how and where different versions of files and directories change. It goes onto show you how conflicts occur and then how to resolve them.

[edit] Prerequisites

You will need the following installed to run this walk through:

svn - subversion client TortoiseSvn (Optional)

[edit] Overview

This walk through will go through the following steps:

  • Create a new repository.
  • Sam (User 1) gets a working copy and commits a few changes.
  • Pat (User 2) gets a working copy.
    • Sam makes a change and commits.
    • Pat makes a change and commits.
  • Pat makes a few changes and commits.
    • Sam updates his out of date working copy.
  • Sam and Pat make some changes and end up with Pat in conflict.
  • Pat resolves her conflict.

During the walk through you can look at the changes both using the svn command line tool and using TortoiseSVN.

[edit] Walk Through: Subversion Administration

This walk through is mainly intended for subversion adminstrators. This walk through will show you how to create a local repository and access it using the file:// schema. The same method is used to create full blown repository but they are configured to be accessed using different schema such as svn:// and http:// etc.

[edit] Bazaar

Bazaar is a distributed version control system. (See: )

[edit] Installing Bazaar

[edit] Ubuntu

[edit] Windows XP

[edit] SourceAnywhere

Dynamsoft SourceAnywhere is a SQL Server-based version control software designed to be a replacement/alternative of Microsoft Visual SourceSafe (VSS).

Both standalone and hosted editions are provided: http://www.dynamsoft.com/Products/version-control-source-control-sourceanywhere.aspx

[edit] SourceAnywhere Standalone

Dynamsoft SourceAnywhere Standalone is a SQL-based source code control software designed to be a replacement/alternative of Microsoft Visual SourceSafe (VSS). It is for developers who are ready to migrate away from Microsoft Visual Source Safe (VSS) source code control for performance, security, scalability, and reliability.

Setup guide

Download 30-day trial

[edit] SourceAnywhere Hosted

SourceAnywhere Hosted online source control is a SQL-based source control software delivered as a SaaS application and it provides all of the key features of Microsoft Visual SourceSafe (VSS), plus much more. SourceAnywhere Hosted online source control is hosted in a Bell Data Center to ensure that you have the most reliable access to mission-critical data and uncompromised security.

Secure your source code

Introduction Video

Sign up for a free hosting plan and have a try

[edit] SCM Anywhere

Dynamsoft SCM Anywhere is a SQL Server-based software configuration management (SCM) tool with fully integrated version control, bug tracking and build automation. It is for teams looking for an integrated solution to manage the whole software development life cycle.

[edit] SCM Anywhere Standalone

Dynamsoft SCM Anywhere Standalone is the SQL-based software configuration management (SCM) solution with fully integrated version control, issue tracking and build automation.

Designed for both centralized and distributed development teams, SCM Anywhere Standalone helps development teams deliver software products faster and promotes team collaboration through centralized control of source code files, team activities, work item status and bug reports.

Setup guide

Overview Video

Free Trial

[edit] SCM Anywhere Hosted

SCM Anywhere Hosted is the world's 1st hosted SCM (software configuration management) solution. It is delivered as a SaaS application and comes with fully integrated version control, issue tracking, build automation and professional service to manage your whole software development life cycle. SCM Anywhere Hosted is hosted in a Bell Data Center to ensure that you have the most reliable access to mission-critical data and uncompromised security.

Secure your source code and digital assets

Sign up for a free plan and have a try

[edit] Git

[edit] References

[edit] Books

Comparing and Merging files with GNU diff and Patch. David MacKenzie, Paul Eggert, Richrd Stallman, Network Theory Ltd