SVN introduction
Subversion (SVN) is an open-source version control system, which means Subversion manages data that changes over time. This data is placed in a central repository. This repository is very much like a normal file server, but it remembers every change to the files. This way you can restore files to older versions, or browse the change history of files.
Some SVN concepts
- **repository:** the place where source code is stored centrally
- **Checkout:** when you do not have the source code on hand, you need to checkout a copy from the repository
- **Commit:** when you have modified the code, you need to commit it to the repository
- **Update:** when you have already checked out a copy of the source code, updating it will synchronize it with the source code on the Repository, and your local code will have the latest changes
The daily development process is actually like this (assuming you have already checked out and worked for a few days): Update (get the latest code) --> make your own modifications and debug successfully --> Commit (everyone can see your modifications).
What if two programmers modify the same file at the same time? SVN can merge both programmers' changes. In fact, SVN manages source code at the line level, meaning as long as the two programmers did not modify the same line, SVN will automatically merge the two modifications. If it is the same line, SVN will prompt a file Conflict, which requires manual confirmation.
Main features of SVN
- (1) Directory version control
CVS can only track the history of individual files, but Subversion implements a "virtual" version-controlled file system that can track changes to entire directories over time. Both directories and files can be version controlled.
- (2) Real version history
Since CVS limits file version records, CVS does not support operations that may happen to files but affect the contents of their containing directory, such as copying and renaming. In addition, in CVS you cannot replace an already-included file with a file of the same name that does not inherit the old version history or is unrelated. In Subversion, you can add, delete, copy, and rename, whether it is a file or a directory. All newly added files start from a new, clean version.
- (3) Automatic commit
A commit action is either fully updated to the repository or not updated at all. This allows developers to create and commit changes in logical intervals, to prevent problems when partial commits succeed.
- (4) Version-controlled metadata
Each file and directory is attached with a set of attribute keywords associated with attribute values. You can create and store any Key/Value pairs you want. Attributes are version controlled over time, just like file contents.
- (5) Choose different network layers
Subversion has an abstract repository access concept that makes it easy to implement new network mechanisms. Subversion can be embedded into the Apache HTTP server as an extension module. This provides Subversion with very advanced stability and interoperability, and also offers many important functions: for example, authentication, authorization, online compression, and repository browsing. There is also a lightweight standalone Subversion server that uses a custom communication protocol and can be easily used via ssh in tunnel mode.
- (6) Consistent data handling
Subversion uses a binary diff algorithm to represent file differences, and it treats text files (human-readable) and binary files (human-unreadable) equally. Both types of files are stored in the repository in compressed form, and file differences are transmitted over the network in both directions.
- (7) Efficient branch and tag
The cost of branching and tagging does not necessarily have to be proportional to the project size. The method Subversion uses to create branches and tags is simply to copy the project, using a method similar to a hard link. So these operations take very little and fixed time.
- (8)Hackability
Subversion has no historical baggage; it is mainly 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
-
1. Atomic commit: A single commit, whether of one or multiple files, is committed as a whole, so either all commits succeed or none succeed, which avoids database incompleteness and data corruption.
-
2. Actions such as renaming, copying, and deleting files are all saved in the version history.
-
3. For binary files, a space-saving storage method is used. (Simply put, it only saves the differences from the previous version.)
-
4. Directories also have version history. The entire directory tree can be moved or copied; the operation is simple and can preserve the complete version record.
-
5. The overhead of branching is very small.
-
6. Optimized database access allows some operations to be performed without accessing the database. This reduces a lot of unnecessary network traffic between the client and the database host.