Web File Version Control
with Subversion:
The Presentation!
Brian Panulla
The IST Solutions Institute
College of Information Sciences and Technology
Penn State University
What is version control?
A version control system can:
- Track all changes to the files that make up your Web project
- Helps you answer certain questions about those files, such as...
Version control can tell you...
- When did file X last change?
- What changed in the file?
- Why was the file changed?
- and...
- Who changed the file?
Version control can save you from...
- Where did my code go?
- Who overwrote my code?
- Why did you overwrite my code?
- and...
- When was the last time we backed up the code?
You might need version control if...
- your servers are littered with files and directories ending in ".bak", ".old", or some sort of datestamp (20060612)
- you're not sure what versions of files are on your development servers
- you're not sure what versions of files are on your production servers
- you employ student developers
- or...
You might need version control if... (cont.)
Version Control Basics
Key Benefits of Version Control
- Revision tracking
- Rollback capability
- Project management features
Revision Tracking
- Every change to every file that makes up your project is versioned:
- Program source code (ASP, PHP, ColdFusion, Python, C++)
- (X)HTML pages
- CSS and JavaScript files
- SQL scripts
- configuration files (XML, ini)
- images*
- documents (Word, PowerPoint, PDF)*
Revision Tracking (cont.)
- Most VC systems will allow you to visually display the differences between versions of a file.
- This generally works only for text-based file formats (HTML, XML, CSS, etc.)
Revision Tracking (cont.)
Revision Tracking (cont.)
- Besides the actual changes to file content, most VC systems will capture:
- the date/time of the change
- the user who made the change
- a comment describing the change
This can help with code reviews and training.
Revision Tracking (cont.)
Rollback Capability
- Version control helps protect your project against bad decisions
- "Undo" changes made in a particular revision or set of revisions
Rollback Capability (cont.)
- You also have the freedom to explore new ideas:
- Revert to last committed revision
- Temporary branches for experimental development
Project Management
- By creating tags and branches, development work can be partitioned into releases.
- Branches and tags can help you prevent untested development code from sneaking onto production servers.
Key Version Control Terminology
- Repository
- Working copy, or sandbox
- Check out
- Check in, or commit
The Repository
- Much like a special-purpose database
- Holds all versions of all files that make up a project
- Can be on your local system, or shared from a server
- Usually shared by multiple projects and multiple users
Working Copy
- A set of files under control of a versioning system
- May be on your local system or on a shared network drive
- Usually owned by one user or developer
Check-out
- The process of making a working copy from a repository.
- May be a rare, or frequent, occurrance depending on your development process and style
Check-in
- The process of submitting changes to files back into the repository
Version Control Models
Two main version control models:
- Lock - modify - unlock (Visual SourceSafe, Dreamweaver, Contribute)
- Copy - modify - merge (Subversion, CVS)
The Versioning Dilemma
- The essential problem of version control begins
when multiple developers share a single code base.
The Versioning Dilemma (cont.)
- Alvin and Ted check out their project code.
The Versioning Dilemma (cont.)
- Alvin commits some changes to file A.
The Versioning Dilemma (cont.)
- Ted commits some other changes to file A.
- Which version of the file (B or B*) should the repository
keep?
The Lock-Modify-Unlock Model
- Alvin checks out file A, locking it. He begins making his changes.
The Lock-Modify-Unlock Model (cont.)
- A little while later, Ted attempts to check out file A, but Alvin's lock prevents this.
Ted must wait for Alvin to complete his changes.
The Lock-Modify-Unlock Model (cont.)
- Finally, Alvin commits his changes to the repository, releasing the lock.
- Ted is notified by this change, either by the VC system, or a simple yell across the office.
The Lock-Modify-Unlock Model (cont.)
- Ted can now check out file A, getting a lock on the file.
The Lock-Modify-Unlock Model (cont.)
- Ted commits his changes to the repository, releasing the lock.
Drawbacks of Lock-Modify-Unlock
- Locks are set at the file level. Generally only one person may have a file locked at a given time,
even if changes are to be made in different parts of the file.
- A file lock generally persists until it is released by the person who obtained the lock, or
it is broken by an administrative override.
The Copy-Modify-Merge Model
- Alvin and Ted each create their own working copies of their project by
checking it out from the repository.
The Copy-Modify-Merge Model (cont.)
- Alvin makes his change, and commits it.
The Copy-Modify-Merge Model (cont.)
- Ted, unaware of Alvin's changes to file A, makes his own
changes. Since his copy of file A is out of date, the
repository prevents his commit.
The Copy-Modify-Merge Model (cont.)
- Ted updates his copy of file A with Alvin's changes from the repository.
Alvin's changes merge uneventfully into Ted's copy of file A, making
a new file that incoporates both Alvin's and Ted's changes.
The Copy-Modify-Merge Model (cont.)
- Ted may now commit his changes to the repository.
- Note: Alvin's working copy is now out of date
with respect to the repository.
Drawbacks of Copy-Modify-Merge
- Merges can occasionally result in a conflict. Conflicts
result when two people have modified the same area of the same file
in two different ways.
- Merges do not work well with most binary file formats, such as Flash
(*.fla) or Photoshop (*.psd) working files, and could end up corrupting the
file. For these files, an update operation generally sends the new version
of the file in it's entirety, rather than attempting to merge the changes.
- This model works best when each developer has their own copy of
the project files. If this is impossible or difficult to accomplish,
locking can sometime still be used.
Using Subversion
Subversion Basics
- Checking out a project
- Adding and committing files
- Modifying files and checking in changes
- Updating your files
- Diffing changes
1. Checking out a project
2. Adding and committing files
3. Modifying files and checking in changes
4. Updating your files
5. Diffing changes
Project Management
Subversion Project Management
- Lines of Development
- Creating a Branch
- Switching your Working Copy to a Branch
- Using Tags
- Checking in Changes to a Branch
- Merging Changes Between Branches
Lines of Development
- The trunk of a project represents the main line of development,
and generally represents the most up-to-date features and content of a project.
- The latest revision in the trunk is called the head revision
Lines of Development
- Branches represent divergent lines of development, are generally of limited
life-expectancy, possibly for experimentation, or to hold code that has been released to customers.
- The latest revision in a branch is called the head revision of that branch.
Lines of Development
- Tags are used to mark critical points in time for a project, such as release dates or the kickoff of a major project.