SVN Introduction


Subversion (SVN) is an open-source version control system, meaning that Subversion manages data that changes over time. This data is placed in a central repository. The repository is very much like an ordinary file server, except that it remembers every change to files. This allows you to restore files to old versions, or browse the history of file changes.


Some concepts of SVN

  • repository (source code repository):A unified place where source code is stored.
  • Checkout (extract):When you don't have the source code on hand, you need to checkout a copy from the repository.
  • Commit (submit):When you have modified the code, you need to commit it to the repository.
  • Update (update):When you have already checked out a copy of the source code, doing an update will synchronize it with the source code in the Repository, and the code on your side 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 (then everyone can see your modifications).

If two programmers modify the same file at the same time, SVN can merge the changes of the two programmers. In fact, SVN manages source code on a line-by-line basis. That is, as long as the two programmers do not modify the same line, SVN will automatically merge both changes. If it is the same line, SVN will prompt that the file has a Conflict, a conflict, which needs manual confirmation.

Main functions of SVN

  • (1) Directory version control

    CVS can only track the history of individual files, but Subversion implements a "virtual" versioned file system that can track changes to entire directories over time. Both directories and files can be version controlled.

  • (2) True version history

    Since CVS restricts version recording of files, CVS does not support operations that may occur on files but affect the contents of the directory they are in, such as copying and renaming. In addition, in CVS you cannot replace a file already added to the system with a file that has the same name but does not inherit the old version history or is completely unrelated. In Subversion, you can add, delete, copy, and rename, whether files or directories. All newly added files start from a new, clean version.

  • (3) Atomic commits

    A commit action either updates everything to the repository or updates nothing at all. This allows developers to create and submit changes in logical units, preventing problems caused by partially successful commits.

  • (4) Version-controlled metadata

    Every file and directory has 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 collaboration capabilities, as well as many important features: for example, authentication, authorization, online compression, and repository browsing, etc. There is also a lightweight standalone Subversion server that uses a custom communication protocol and can be easily used in tunnel mode through ssh.

  • (6) Consistent data handling

    Subversion uses a binary diff algorithm to represent differences between files. It treats both text files (human-readable) and binary files (not human-readable) equally. Both types of files are stored in compressed form in the repository, and file differences are transmitted over the network in both directions.

  • (7) Efficient branching and tagging

    The cost of branching and tagging does not necessarily have to be proportional to project size. Subversion's method of creating branches and tags is simply to copy the project, using a method similar to hard links. Therefore, these operations only take a small, fixed amount of time.

  • (8)Hackability

    Subversion has no historical baggage; it is mainly a set of shared C libraries with well-defined APIs. This makes Subversion easy to maintain and usable by other applications and programming languages.

Advantages over CVS

  • 1、Atomic commits: A commit, whether for a single file or multiple files, is submitted as a whole, so either all succeed or all fail. This prevents database incompleteness and data corruption.

  • 2. Actions such as renaming, copying, and deleting files are all recorded in version history.

  • 3. For binary files, a space-saving storage method is used. (Simply put, it only stores the differences from the previous version.)

  • 4. Directories also have version history. The entire directory tree can be moved or copied, the operation is very simple, and all version records can be preserved.

  • 5. The cost 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.

Other extensions