1. Planning and Managing Software Projects 2011-12
Revision control systems
Emanuele Della Valle, Lecturer: Daniele Dell’Aglio
http://emanueledellavalle.org
2. Outline
● Why revision control
● Main concepts
● Basic operations
– Checkout
– Commit
– Update
● Branches and tags
Planning and Managing Software Projects – Emanuele Della Valle
3. Motivations
When working alone
• Backup copy Repository
• We don’t want to
lose the history of
our F F F
code/documents/etc. r5 r4 r3
...
F
r5
Planning and Managing Software Projects – Emanuele Della Valle
4. Motivations
When working alone
• Backup copy Repository
• We don’t want to
lose the history of
our F F F
code/documents/etc. r5 r4 r3
...
When working in
team F
• Share modifications F r5
easily r5
• Support for
cooperative code F
development r5
Planning and Managing Software Projects – Emanuele Della Valle
5. SVN
There are several version control systems (both open
and closed source)
• CVS
• SVN
• Perforce
In the following we will consider SVN
• The main concept are similar in the other systems
Several GUIs for SVN are available
• TortoiseSVN (Windows)
• RabbitVCS (Linux)
• Subclipse/Subversive (Eclipse plug-ins)
• ...
Planning and Managing Software Projects – Emanuele Della Valle
6. Some definitions
Repository
Repository
(the location
where files
are stored)
F F F ...
r5 r4 r3
F
r5
Planning and Managing Software Projects – Emanuele Della Valle
7. Some definitions
Repository
Repository
F F F ...
r5 r4 r3
Revision
F
(Version)
r5
(an identifier
associated to
each version of
the file)
Planning and Managing Software Projects – Emanuele Della Valle
8. Some definitions
Repository
Repository
Head
(the most
recent version F F F ...
of the files) r5 r4 r3
Revision
F
(Version)
r5
Planning and Managing Software Projects – Emanuele Della Valle
9. Some definitions
Repository
Repository
Head
F F F ...
r5 r4 r3
Revision
F
(Version)
r5
Working copy
(copy of the
files on the
local machine)
Planning and Managing Software Projects – Emanuele Della Valle
10. Main operations
Check-out: initial Repository
creation of the working
copy from the repository
F F F ...
r5 r4 r3
F
r5
svn checkout <URL>
Planning and Managing Software Projects – Emanuele Della Valle
11. Main operations
Check-out: initial Repository
creation of the working
copy from the repository
F F F ...
r5 r4 r3
F
r5
Planning and Managing Software Projects – Emanuele Della Valle
12. Main operations
Check-out: initial Repository
creation of the working
copy from the repository
F F F ...
r5 r4 r3
F
r5*
Planning and Managing Software Projects – Emanuele Della Valle
13. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r5 r4 r3
update of the HEAD
revision with the working
copy F
r5*
F
r5*
svn commit
Planning and Managing Software Projects – Emanuele Della Valle
14. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r6 r5 r4
update of the HEAD
revision with the working
copy
F
r6
svn commit
Planning and Managing Software Projects – Emanuele Della Valle
15. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r6 r5 r4
update of the HEAD
revision with the working
copy
F
r6*
Planning and Managing Software Projects – Emanuele Della Valle
16. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r6 r5 r4
update of the HEAD
revision with the working
copy F
r6
Revert: drop the
modification on the F
working copy and reset r6*
the files to HEAD
svn revert <file>
Planning and Managing Software Projects – Emanuele Della Valle
17. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r6 r5 r4
update of the HEAD
revision with the working
copy
Revert: drop the
modification on the F
working copy and reset r6
the files to HEAD
Planning and Managing Software Projects – Emanuele Della Valle
18. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r6 r5 r4
update of the HEAD
revision with the working
copy
Revert: drop the
modification on the F
working copy and reset r6*
the files to HEAD
Planning and Managing Software Projects – Emanuele Della Valle
19. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r9 r8 r7
update of the HEAD
revision with the working
copy
Revert: drop the
modification on the F
working copy and reset r6*
the files to HEAD
Planning and Managing Software Projects – Emanuele Della Valle
20. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r9 r8 r7
update of the HEAD
revision with the working
copy F
r9
Revert: drop the
modification on the F
working copy and reset r6*
the files to HEAD
Update: merge HEAD svn update
and the working copy
Planning and Managing Software Projects – Emanuele Della Valle
21. Main operations
Check-out: initial creation Repository
of the working copy from
the repository
Check-in (Commit): F F F ...
r9 r8 r7
update of the HEAD
revision with the working
copy
Revert: drop the
modification on the F
working copy and reset r9*
the files to HEAD
Update: merge HEAD
and the working copy
Planning and Managing Software Projects – Emanuele Della Valle
22. Main operations
The main commands we see in the previous slides are
• svn checkout <URL>
• svn commit
• svn revert <file>
• svn update
Two additional important commands are:
• svn add <file> [<file>...]
• svn delete <file> [<file>...]
add and delete respectively adds and removes
files in/from the working copy
• Those operations should then be confirmed (with a
commit) or cancelled (through a revert)
Planning and Managing Software Projects – Emanuele Della Valle
23. Conflicts
A conflict occours when the system is unable to
automatically merge a working copy with the HEAD
revision
Usually this issue can be found when developing in
team
Example:
• Two users check-out the same release
• They both modify the same files in their working copy
• The first user commits his working copy
• The second one tries to commit and the system is
unable to merge
Best practice: before committing, do an update and
resolve the conflict locally!
Planning and Managing Software Projects – Emanuele Della Valle
24. Branches
A branch is a copy of the project
• The original is stored in the Trunk
It is maintained separately
Trunk
Branch 2
Branch 1
There is only one trunk, while there are zero or more
branches
• Example: team works in separated branches to include
new features
SVN doesn’t have a dedicated command to create
branches:
svn copy <from> <to>
Planning and Managing Software Projects – Emanuele Della Valle
25. Merges
Modifications done in the branches should then be
applied to the trunk/other branches
In general, merge in SVN:
• Compares two different trees
• Extract the differences between the two trees
• Differences are applied to the working copy
The merge command is
svn merge –r<from>:<to> <url>
As other operations, merge is done locally
• It should be committed (or reverted)
Planning and Managing Software Projects – Emanuele Della Valle
26. Tags
Tags identify relevant revisions
Each tag is a label associated to a revision
Tags can be used to identify
• Milestones
• Software releases
Repository
release-1.1 release-1.0
F
FF F
FF F
FF F
FF F
FF F
FF ...
r9
r8
r8 r8
r8
r8 r7
r8
r8 r6
r8
r8 r5
r8
r8 r4
r8
r8
Planning and Managing Software Projects – Emanuele Della Valle
27. Distributed version control systems
Distributed version control systems are an alternative
to che (centralized) version control systems
They adopt a peer to peer approach instead of a
server-client one
• Several distributed repositories
Examples of distributed version control systems
• Git
• Mercurial
• Baazar
Planning and Managing Software Projects – Emanuele Della Valle
28. Useful links
Version Control with Subversion http://svnbook.red-
bean.com/
A Visual Guide to Version Control
http://betterexplained.com/articles/a-visual-guide-to-
version-control/
Pro Git http://git-scm.com/book
Planning and Managing Software Projects – Emanuele Della Valle