Home  >  Article  >  Development Tools  >  Detailed explanation of the difference between GIT and SVN

Detailed explanation of the difference between GIT and SVN

Guanhui
Guanhuiforward
2020-07-18 17:44:175043browse

Detailed explanation of the difference between GIT and SVN

GIT is not only a version control system, it is also a content management system (CMS), work management system, etc. If you are someone with a background in using SVN, you need to make some mental changes to adapt to some of the concepts and features provided by GIT. Therefore, the main purpose of this article is to help you understand it by introducing what GIT can do and how it is different from SVN on a deeper level.

1. GIT is distributed, SVN is not:

This is the core of GIT and other non-distributed version control systems, such as SVN, CVS, etc. difference. If you can understand this concept, you're halfway there. A little disclaimer needs to be made, GIT is not the first or only distributed version control system currently. There are also some systems, such as Bitkeeper, Mercurial, etc., that also run in distributed mode. But GIT does a better job in this regard and has more powerful features.

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 without Internet access, such as on an airplane, in a basement, in an elevator, etc., you can still submit files, view historical version records, create project branches, etc. 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.

Similarly, this distributed operating mode is also a huge gift to the development of the open source software community. You no longer have to make patch packages and send them out by email as before, you only need to create A branch that sends a push request to the project team. This keeps your code up to date and not lost in transit. GitHub.com is such an excellent case.

Some rumors have spread that future versions of subversion will also be based on distributed mode. But at least it's not visible yet.

2. GIT stores content by metadata, while SVN stores content by file:

All resource control systems hide the metainformation of files in a In folders like .svn, .cvs, etc. If you compare the size of the .git directory with that of .svn, you will find that they are very different. 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.

3. GIT branches are different from SVN branches:

Branches are nothing special in SVN, they are 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. Thanks to classmate Ben for pointing out this feature. Therefore, it often happens that some branches are missed.

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.

4. GIT does not have a global version number, but SVN has:

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.

Update: Some readers pointed out that we can use GIT's SHA-1 to uniquely identify a code snapshot. This does not completely replace the easy-to-read numerical version numbers in SVN. However, the purpose should be the same.

5. The content integrity of GIT 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. There is a good discussion about GIT content integrity here - http://stackoverflow.com/questions/964331/git-file-integrity

Are these the only five differences between GIT and SVN? of course not. I guess these 5 are just the "most basic" and "most attractive" ones.

Introduction to the difference between git and svn

Why version control is needed

Git and svn are both used by programmers to manage code. If When one person develops a project, version control is of no use at all, right? However, when developing in an enterprise, it is almost impossible for one person to be responsible for a project. From requirements review, UI design, front-end development, back-end development, and testing, the entire process requires the cooperation of a team. At this time, version control is particularly important.

Difference

Let’s talk about the difference between git and svn:

svn is a centralized version control system, and git is a distributed version control system.
I believe many people have heard this sentence. What is centralized and distributed? Obviously, literally speaking, in svn, everyone modifies the program on the server. If someone modifies the same part, there will be a conflict. Therefore, the general team will agree that for the public part of the program, try to mark the developer's unique identification, or add A from the top and B from the bottom.
Git is when developers create their own branches. This branch is equivalent to copying the source code on the local machine. All subsequent modifications are local codes. The server code can be pulled at any time for synchronization. Git can create countless For branches, developers only need to submit their modified code, so the chance of conflicts will be much smaller.
SVN interacts directly with the server, while git caches the project locally and then pushes it to the server.
svn must work when connected to the Internet, but git can be developed without the Internet.
Svn is prone to conflicts, but git is not prone to conflicts.
svn is designed for project management, and git is designed for code management.
svn is suitable for multi-project parallel development, and git is suitable for single-project development.
svn is suitable for internal enterprises, where the project manager coordinates the overall development of multiple projects. git is suitable for multiple people to develop the same project through the network.

git and github

Create a sentence to reflect the relationship between the two
mio used git to submit the project to github
In other words: git is a tool and github is a platform.

Finally

I don’t know who I heard before, the meaning of writing a technical blog is not to remember, but to teach. This sentence really makes sense. Although the words I write now are very unprofessional and look like an amateur, I will try my best.

The following is Baipaojun’s addition

Only when one is understood and thought in place can it be targeted when implemented. The other several can only be realized when they are used

1) The core difference is that Git is distributed, while Svn is not distributed. If you understand this, it will be easy to get started. Let me state that Git is not the only distributed version control system currently. There are also Mercurial, etc., so they are pretty much the same. Having said that, like Svn, Git has its own centralized repository and server, but Git is more inclined to distributed development, because every developer has a Local Repository on their computer, so they can commit even if there is no network. View Historical version records, creating project branches and other operations, wait until the network is connected again and push to the server.

From the above, Git looks really great, but Git adds Complexity, which may make you a little confused at first, because you need to build two Repositories (Local Repositories & Remote Repositories), and there are many instructions. In addition, you need Know which instructions are in the Local Repository and which instructions are in the Remote Repository.

2) Git stores content as metadata, while SVN stores content as files: because the .git directory is a cloned version of the repository on your machine, and it has all the contents of the central repository. Things like tags, branches, version records, etc. Comparing the size of the .git directory with that of .svn, you will find that they are very different.

3) Git does not have a global version number, but SVN does: So far, this is the biggest feature that Git lacks compared to SVN.

4) The integrity of Git’s content is better than that of 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.

5) After downloading Git, you can see all Logs in OffLine state, but not SVN.

6) One thing that is very annoying at the beginning is that SVN must be updated before committing. If you forget to merge, some errors will occur. This situation is relatively rare in git.

7) Clone a brand new directory. For example, if it also has five branches, SVN copies 5 versions of files at the same time, which means repeating the same action five times. Git just gets the elements of each version of the file, and then only loads the main branch (master). In my experience, a clone has nearly 10,000 commits (commits), five branches, each branch has about 1500 The SVN file took nearly an hour! And Git only took a mere 1 minute!

8) Repository: SVN can only have one designated central repository. When there is a problem with this central repository, all working members are paralyzed until the repository is repaired or a new repository is established. Git can have unlimited repositories. Or, to be more correct, every Git is a repository, the difference is whether they have an active directory (Git Working Tree). If something happens to the main repository (for example, the repository placed on GitHub), working members can still commit in their local repository and wait for the main repository to be restored. Working members can also commit to other repositories!

9) Branch (Branch) In SVN, a branch is a complete directory. And this directory has complete actual files. If a staff member wanted to start a new branch, it would impact "the whole world"! Everyone will have the same branch as you. If your branch is used for sabotage work (security testing), it will be like an infectious disease. If you change a branch, others will have to re-cut the branch and download it again, which is very bloody. With Git, each working member can open unlimited branches in his or her own local repository. For example: When I want to try to break my own program (security test), and want to keep these modified files for future use, I can open a branch and do what I like. No need to worry about getting in the way of other staff members. As long as I don't merge and commit to the main repository, no one at work will be affected. When I no longer need this branch, I just delete it from my local repository. Painless and itchy.

Git branch names can use different names. For example: My local branch is named OK, but the name in the main repository is actually master.

The most noteworthy thing is that I can open a branch at any commit point in Git! (One method is to use gitk –all to observe the entire submission record, and then open the branch at any point.)

10) Submit (Commit) In SVN, when you submit your finished product, it will directly Recorded to the central repository. When you discover something seriously wrong with your finished product, there's nothing you can do to stop it from happening. If the network is down, you can't submit at all! Git submissions are entirely activities in the local repository. And you just "git push" to the main repository. Git's "push" is actually performing "synchronization" (Sync).

Finally, to summarize:

The characteristic of SVN is that it is simple. It is OK to use when you just need a place to put the code.

Git's features version control can do anything without relying on the network, and has better support for branches and merges (of course this is what developers are most concerned about), but I want you to use it better, you need Take the time to try it out.

The above is the detailed content of Detailed explanation of the difference between GIT and SVN. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete