Version control

When working with other programmers, especially if you are not in close proximity, you may find at one point that two people are working on the same PHP script at the same time. When they hit "Save", should the computer overwrite what the last programmer did, or should it bring up an error message and exit? Furthermore, what happens if a code problem crops up, and people want to revert to a previous version of a file?

These two problems are solved in the guise of version control, which is a centralised database of all files in your project. When a programmer wants to edit a script, they "check out" the script for editing. Other programmers who want to edit the script will see a notice that programmer A has checked it out, so they can choose whether to come back later or edit the same script anyway. When scripts are returned to the repository ("checked in", or "committed"), the version control system stores the new file version (as well the old versions) and allows others to read it. If two programmers commit a new script at the same time, the second programmer will receive a notice that someone has changed the file since they checked it out, and has the option of merging their changes and the other changes into a final file. This might sound risky, but in practice it works just fine most of the time.

Version control also adds a degree of change-tracking to your project. For example, if programmer B changes a file last edited by programmer A, that change will be recorded in the version control archive. If there is later a problem, the "culprit" can be tracked down and asked to fix it - or, perhaps better, the previous version of the code can be used instead. By storing each individual file version in its archive, you can also check differences between versions - you can compare v1.1 of a file against v2.1 of a file and see who made what code contributions and when they were released.

Using version control is pretty much mandatory for group programming - if you use Unix you probably have CVS (Concurrent Versions System) installed already. Windows programmers can also use CVS, but many use Microsoft's SourceSafe package, which integrates directly into Visual Studio. There are cross-platform version control systems available - a popular system is Seapine Surround SCM, which works smoothly on both Windows and Linux.

 

Next chapter: Documenting your project >>

Previous chapter: How to develop code

Jump to:

 

Home: Table of Contents

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar