SVN Introduction
Subversion (SVN) is an open-source version control system. This means that Subversion manages data that changes over time. This data is stored in a central repository. The repository is similar to an ordinary file server, but it remembers every change made to the files. This allows you to revert files to older versions or browse the history of changes.
Some SVN Concepts
- Repository: The centralized location where source code is stored.
- Checkout: When you do not have the source code, you need to checkout a copy from the repository.
- Commit: When you have made changes to the code, you need to commit them to the repository.
- Update: When you have a copy of the source code, updating it will synchronize your local copy with the latest changes in the repository.
The typical development process is as follows (assuming you have already checked out and have been working for a few days): Update (to get the latest code) --> Make your changes and debug --> Commit (so others can see your changes).
If two developers modify the same file simultaneously, SVN can merge their changes. SVN manages source code at the line level, so unless both developers modify the same line, SVN will automatically merge the changes. If the same line is modified, SVN will flag a conflict that requires manual resolution.
Main Features of SVN
- (1) Directory Version Control
Unlike CVS, which can only track the history of individual files, Subversion implements a "virtual" version control file system that tracks changes to entire directories over time. Both directories and files can be version controlled.
- (2) True Version History
Unlike CVS, which limits file version records, Subversion supports operations that affect directory contents, such as copying and renaming. In Subversion, you can add, delete, copy, and rename files and directories. All new files start with a clean, new version.
- (3) Atomic Commit
A commit action is either fully updated to the repository or not updated at all. This allows developers to make and commit changes in logical intervals, preventing issues when partial commits succeed.
- (4) Version-Controlled Metadata
Each file and directory is associated with a set of attribute keywords and values. You can create and store any key/value pairs you want. These attributes are version-controlled over time, just like file content.
- (5) Choice of Network Layer
Subversion has an abstract concept of repository access, making it easy to implement new network mechanisms. Subversion can be embedded as an extension module in the Apache HTTP Server, providing advanced stability, collaboration, authentication, authorization, online compression, and repository browsing. There is also a lightweight standalone Subversion server that uses a custom communication protocol, easily tunneled via SSH.
- (6) Consistent Data Handling
Subversion uses a binary difference algorithm to represent file differences, treating text (human-readable) and binary (non-human-readable) files equally. Both types of files are stored in compressed form in the repository, and file differences are transmitted in both directions over the network.
- (7) Efficient Branching and Tagging
The cost of branching and tagging does not have to be proportional to the size of the project. Subversion creates branches and tags by copying the project, similar to hard linking. These operations are small and take a fixed amount of time.
- (8) Hackability
Subversion has no historical baggage; it is primarily a set of shared C libraries with a well-defined API. This makes Subversion easy to maintain and usable by other applications and programming languages.
Advantages Over CVS
- Atomic Commit: A commit, whether of single or multiple files, is treated as a whole, ensuring that either all changes are committed or none are, preventing database inconsistency and data corruption.
- Preservation of Rename, Copy, and Delete Operations: These actions are stored in the version history.
- Space-Saving Storage for Binary Files: Only differences from the previous version are stored.
- Directory Version History: The entire directory tree can be moved or copied while retaining all version records.
- Minimal Branching Overhead: Branching is very efficient. Optimized database access allows certain operations to be performed without accessing the database, thereby reducing unnecessary network traffic between the database host and the client.