Home  >  Article  >  Development Tools  >  What are the differences between git and svn?

What are the differences between git and svn?

青灯夜游
青灯夜游Original
2021-11-26 15:27:2832334browse

Difference: 1. SVN is a centralized version control system, while Git is a distributed version control system; 2. SVN is stored according to the original file, which is larger in size, while Git is stored according to metadata. , the size is very small; 3. Git's branch operations will not affect other developers, but SVN will.

The operating environment of this tutorial: Windows 7 system, Git version 2.30.0, Dell G3 computer.

Introduction to svn and git

SVN (Centralized version control system)

SVN is the abbreviation of Subversion and is an open source version control system, supporting most common operating systems. As an open source version control system, Subversion manages data that changes over time. This data is placed in a central repository. This archive is much like a regular file server, but it remembers every file change. This way you can restore the file to an older version or browse the file's change history. Subversion is a general-purpose system that can be used to manage any type of file, including program source code.

Workflow

The workflow of centralized management is as follows:

The core of centralized code management It's a server, and all developers must get code from the server before starting a new day's work, then develop, and finally resolve conflicts and commit. All version information is placed on the server. If you are disconnected from the server, it can basically be said that developers are unable to work. The following is an example:

Start a new day’s work:

  • Download the latest code of the project team from the server.

  • Enter your own branch, work on it, and submit code to your own branch on the server every hour (many people have this habit. Because sometimes they change the code by themselves) , and finally want to restore to the version of the previous hour, or see what code you modified in the previous hour, you need to do this).

  • The off-duty time is coming soon. Merge your branch to the main branch of the server. The day's work is completed and reflected to the server.

SVN is a centralized version control system

This approach brings many benefits, especially compared to the old-fashioned local VCS. Now, everyone can see to some extent what others in the project are working on. Administrators can also easily control the permissions of each developer.
There are two sides to everything, good and bad. The most obvious disadvantage of doing this is that the central server is a single point of failure. If it is down for one hour, no one will be able to submit updates, restores, comparisons, etc. during this hour, and it will be impossible to work together. If the central server's disk fails and no backup is made or the backup is not timely enough, there is a risk of data loss. The worst case scenario is to completely lose all historical change records of the entire project, except for some snapshot data extracted by the client, but this is still a problem, and you cannot guarantee that all the data has been extracted.
In principle, Subversion only cares about the specific differences in file content. Each time it is recorded which files have been updated, and which lines and contents have been updated.

Features of Subversion

  • Each repository has a unique URL (official address), and each user obtains code and data from this address;

  • To obtain code updates, you can only connect to this unique repository and synchronize to obtain the latest data;

  • Submissions must have a network connection (non-local Repository);

  • Submission requires authorization. If there is no write permission, submission will fail;

  • Submission does not succeed every time. If someone else submits before you, it will prompt "The changes are based on an outdated version, update first and then submit"... and so on;

  • Conflict resolution is a competition of submission speed: those who are quick, Submit first, and nothing will happen; if you are slow, submit later, you may encounter troublesome conflict resolution.

GIT (Distributed Version Control System)

Git is a free, open source distributed version control system for agile and efficient processing of any small or Large projects

Git is an open source distributed version control system, used to effectively and quickly handle version management of projects from small to very large. Git is an open source version control software developed by Linus Torvalds to help manage Linux kernel development.

The biggest difference between distributed and centralized is that developers can submit locally, and each developer copies a complete Git repository on the local machine by cloning (git clone).

Workflow

The picture below is the classic git development process.

Functional features of Git

From the perspective of a general developer, git has the following functions:

  1. Clone the complete Git repository (including code and version information) from the server to a single machine.
  2. Create branches and modify code on your own machine according to different development purposes.
  3. Submit the code on the branch you created on a single machine.
  4. Merge branches on a single machine.
  5. Fetch the latest version of the code on the server, and then merge it with your main branch.
  6. Generate a patch and send the patch to the main developer.
  7. Looking at the feedback from the main developer, if the main developer finds that there is a conflict between two general developers (a conflict that can be resolved cooperatively between them), they will be asked to resolve the conflict first, and then let them resolve the conflict. Submitted by one person. If the lead developer can resolve it himself, or there are no conflicts, pass.
  8. The general method for resolving conflicts between developers is that developers can use the pull command to resolve conflicts, and then submit patches to the main developer after the conflicts are resolved.

From the perspective of the main developer (assuming that the main developer does not need to develop code), git has the following functions:

  1. View Check the submission status of general developers through email or other methods.

  2. Apply patches and resolve conflicts (you can resolve them yourself, or you can ask developers to resolve them before resubmitting. If it is an open source project, you also need to decide which patches are useful and which are not) .

  3. Submit the results to a public server and then notify all developers.

Git is a distributed version control system

Since its birth in 2005, Git has become increasingly mature and perfect. While being highly easy to use, it still retains the original design set goals. It is fast and extremely suitable for managing large projects. It also has an incredible non-linear branch management system that can cope with various complex project development needs.

Unlike SVN, Git records version history and only cares about whether the overall file data has changed. Git does not save differential data about changes in file content. In fact, Git is more like taking a snapshot of the changed files and recording them in a miniature file system. Each time an update is submitted, it scans the fingerprint information of all files, takes a snapshot of the file, and then saves an index pointing to the snapshot. To improve performance, if the file has not changed, Git will not save it again, but will only make a connection to the last saved snapshot.

Git features

  1. The repository of each clone in Git is equal. You can clone any repository to create your own repository, and your repository can also be used as a source for others if you wish.
  2. Every extraction operation of Git is actually a complete backup of the code repository. Submission is completely done locally, no one needs to give you authorization, you are the master of your repository, and submission will always be successful.
  3. Even changes based on the old version can be submitted successfully, and the submission will create a new branch based on the old version.
  4. Git submissions will not be interrupted until you are completely satisfied with your work. PUSH to others or others to PULL your repository. Merging will occur during the PULL and PUSH processes. Conflicts that cannot be resolved automatically will You are prompted to complete this manually.
  5. Conflict resolution is no longer like a submission competition like SVN, but merging and conflict resolution are performed when needed.

The difference between svn and git

  • SVN is a centralized version control system. There is an inaccurate metaphor: SVN = version control backup server SVN It feels a bit like an archive warehouse when used. It supports parallel reading and writing of files, and supports version management of code. Its functions include retrieval, import, update, branch, rename, restore, merge, etc.

    Git is a distributed version control system. The operation commands include: clone, pull, push, branch, merge, push, rebase. Git is good at version management of program code.

  • GIT, like SVN, has its own centralized repository or server. However, GIT prefers to be used in a distributed mode, that is, each developer will clone his or her own repository on his or her own machine after checking out the code from the central repository/server.

    It can be said that if you are trapped in a place where you cannot connect to the Internet, such as on an airplane, in a basement, in an elevator, etc., you can still submit files, view historical version records, and create project branches. wait. To some, this may not seem to be of much use, but when you suddenly encounter an environment without network, this will solve your big trouble.

  • Git stores files in the form of metadata, which is very small; SVN stores files in the form of original files, which is larger in size.

    GIT stores content as metadata, while SVN stores content as files. All resource control systems hide the metainformation of files in a folder similar to .svn, .cvs, etc.

    If you compare the size of the .git directory with that of .svn, you will find that there is a big gap between them. Because the .git directory is a cloned version of the repository on your machine, it has everything on the central repository, such as tags, branches, version records, etc.

  • The branch is nothing special in SVN, it is just another directory in the repository. If you want to know whether a branch has been merged, you need to manually run a command like svn propget svn:mergeinfo to confirm whether the code has been merged.

    However, working with GIT branches is quite simple and fun. You can quickly switch between several branches from the same working directory. You can easily find unmerged branches, and you can merge these files quickly and easily.

  • GIT does not have a global version number, while SVN does. So far, this is the biggest feature that GIT lacks compared to SVN. You also know that the SVN version number is actually a snapshot of the source code at any corresponding time. I think it is the biggest breakthrough in the evolution from CVS to SVN. Because GIT and SVN are conceptually different, I don't know what features in GIT correspond to them. If you have any clues, please share them in the comments.

  • GIT's content integrity is better than SVN: GIT's content storage uses the SHA-1 hash algorithm. This ensures the integrity of code content and reduces disruption to the repository in the event of disk failures and network problems.

  • The impact of branch operations

    Git's branch operations will not affect other developers; but SVN will. When you create a new branch, everyone will have the same information as you Same branch.

The advantages and disadvantages of svn and git

The advantages and disadvantages of SVN

SVN has good support for Chinese, easy operation, and no difficulty in use. Artists, product personnel, testers, and implementation personnel can all easily get started. The user interface is unified, the functions are complete, and the operation is convenient.

Advantages and Disadvantages of Git

Performs differentiated version management on program source code, and the code base occupies very little space. Easy to branch code management. It does not support Chinese, has poor graphical interface support, and is difficult to use. Not easy to promote.

The difference between the applicable scopes of svn and git

  • The applicable objects are different. Git is suitable for developers involved in open source projects. Because of their high level of expertise, they care more about efficiency than ease of use. SVN is different, it is suitable for ordinary company development teams. It's easier to use.

  • The occasions used are different. Git is suitable for the development of a single project with multiple development roles through the Internet, and SVN is suitable for the development of multiple parallel projects within the enterprise coordinated by project managers.

  • Permission management strategies are different. Git does not have strict permission management control. As long as you have an account, you can export, import code, and even perform rollback operations. SVN has strict permission management, and can control permissions for a certain subdirectory by group or individual. Distinguish between read and write permissions. More strictly, rollback operations are not supported. Make sure the code is always traceable.

  • The usage scope of branches is different. In Git, you can only branch the entire warehouse, and once deleted, it cannot be restored. In SVN, branch can target any subdirectory, which is essentially a copy operation. Therefore, you can create many hierarchical branches, delete them when they are not needed, and just check out the old SVN version when needed in the future.

  • Based on the third point, Git is suitable for pure software projects, typically some open source projects, such as the Linux kernel, busybox, etc. On the contrary, SVN is good at multi-project management. For example, you can store the bsp/design document/file system/application/automated compilation script of a mobile phone project in an SVN warehouse, or store the file systems of five mobile phone projects in an SVN. n (number of projects)*m (number of components) repositories must be established in git. In SVN, only up to n or m are needed.

  • Git uses a 128-bit ID as the version number , and you must indicate which branch it is when checking out, while SVN uses an incrementing serial number as the globally unique version No., more concise and easy to understand. Although you can use gittag to create some literal aliases, after all, that is only for special versions.

  • Traceability, the typical development process of git is: establish a branch, develop, submit to the local master, and delete the branch. The consequence of this is that previous modification details will be lost. And do the same thing under SVN without losing any details. Here is an interesting link that shows the typical working method under git: (with master as the core, constantly creating new branches and deleting old branches)

  • Partial update, partial restore. Since SVN creates a .svn folder in each folder for management, it can easily implement partial updates or restores. If you only want to update certain parts, svn can do it very well. At the same time, if the code is written incorrectly, partial restoration can be easily achieved. Of course, git can also be restored through historical versions, but partial restoration cannot be easily achieved.

Which one is more suitable for project management, SVN or Git?

First of all, I am a project manager of a R&D team. I have used both SVN and Git. SVN is more suitable for project management, and Git is only suitable for code management.

Members of a R&D team normally include: requirements analysis, design, artists, programmers, testing, implementation, operation and maintenance. Each member has output in their work, including documents, design code, and program code. These need to be managed centrally by project. SVN can clearly classify and manage by directory, keeping the management of the project team in an orderly and efficient state.

Recommended learning: "Git Tutorial"

The above is the detailed content of What are the differences between git and svn?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does git add mean?Next article:What does git add mean?