Complete git tutorial: 001—Introduction to Git

Introduction to git

What is git

Git is currently the most advanced distributed version control system in the world (no one)

effect

So what is a version control system ?

If you have written a long story in Microsoft Word, then you must have this experience:

I want to delete a paragraph, but I'm afraid that I won't be able to find it again in the future. There is a way, first "save the current file as..." a new Word file, then change it to a certain extent, and then "save as..." a new file, so that you keep changing, and finally your Word document changes It became like this: after
Insert picture description here
a week, you want to retrieve the deleted text, but you can't remember which file it was saved in before deleting it, so you have to look for it one by one, which is really troublesome.

Looking at a bunch of messy files, I want to keep the newest one, and then delete the others. I'm afraid that I will use it someday, so I dare not delete it. I'm really depressed.

Even worse, some parts need your financial colleagues to help fill in, so you copy the file to the U disk to her (you may also send a copy to her via Email), and then you continue to modify the Word file. One day later, your colleague will send you the Word file again. At this time, you must think about what changes you have made after you send it to her until you receive her file. You have to merge your changes with her part. It's difficult.

So you think, if there is a software, not only can it automatically record every file change for me, but also allow colleagues to edit collaboratively, so that you don't have to manage a bunch of similar files by yourself, and you don't need to pass the files back and forth. If you want to check a certain change, just glance at it in the software. Isn't it very convenient?

This software should be used like this, it can record every file change: in
Insert picture description here
this way, you end the prehistoric era of manual management of multiple "versions" and enter the 20th century of version control.

The birth of Git

Many people know that Linus created the open source Linux in 1991. Since then, the Linux system has continued to develop and has become the largest server system software.

Although Linus created Linux, the growth of Linux depends on the participation of enthusiastic volunteers from all over the world. So many people write code for Linux all over the world, how is the code of Linux managed?

The fact is that before 2002, volunteers from all over the world sent the source code files to Linus via diff, and then Linus himself merged the code manually!

You might be thinking, why doesn't Linus put the Linux code in the version control system? Isn't there a free version control system like CVS and SVN? Because Linus firmly opposes CVS and SVN, these centralized version control systems are not only slow, but also must be connected to the Internet to be used. There are some commercial version control systems. Although they are easier to use than CVS and SVN, they are paid and not in line with the open source spirit of Linux.

However, in 2002, the Linux system had been developed for ten years. The size of the code base made it difficult for Linus to continue to manage it manually. The brothers in the community also expressed strong dissatisfaction with this approach, so Linus chose a business The version control system BitKeeper, the owner of BitKeeper, BitMover, out of humanitarian spirit, authorized the Linux community to use this version control system for free.

The great situation of stability and unity was broken in 2005, because the gathering of great talents in the Linux community inevitably contaminated the social habits of some Liangshan heroes. Andrew, who developed Samba, tried to crack BitKeeper's protocol (it was not the only one who did this), but was discovered by BitMover (monitoring was done well!), so BitMover became angry and wanted to take back the free use rights of the Linux community.

Linus can apologize to BitMover and promise to discipline the brothers strictly in the future. Well, this is impossible. The actual situation is this:

It took Linus two weeks to write a distributed version control system in C. This is Git! Within a month, the source code of the Linux system was managed by Git! How is the cow defined? Everyone can experience it.

Git has quickly become the most popular distributed version control system. Especially in 2008, the GitHub website was launched. It provides free Git storage for open source projects. Numerous open source projects have begun to migrate to GitHub, including jQuery, PHP, Ruby, and so on.

History is just such an accident. If it weren't for BitMover's threat to the Linux community, maybe now we don't have a free and super easy-to-use Git.

Centralized and distributed

The CVS and SVN that Linus has always hated are centralized version control systems, while Git is a distributed version control system. What is the difference between centralized and distributed version control systems?

Let’s talk about the centralized version control system first. The version library is stored on the central server. When you work, you use your own computer. Therefore, you must first obtain the latest version from the central server, and then start to work. Live, then push your own live to the central server.

The central server is like a library. If you want to change a book, you must first borrow it from the library, then go home to change it yourself, and then put it back in the library after you change it.

Insert picture description here
The biggest problem of the centralized version control system is that it must be connected to the Internet to work . If it is okay in the local area network, the bandwidth is large enough, and the speed is fast enough, but if you encounter a slow network speed on the Internet, you may need to submit a 10M file. 5 minutes, this is not enough to suffocate people to death

The difference between distributed and centralized version control systems

First of all, the distributed version control system does not have a "central server" at all. Everyone’s computer is a complete version library. In this way, when you work, you don’t need to be connected to the Internet because the version library is on your own computer. .

Since everyone has a complete repository on their computer, how can multiple people collaborate? For example, you change file A on your computer, and your colleague also changes file A on his computer. At this time, you two only need to push your changes to each other, and you can see each other's edited.

Compared with the centralized version control system, the security of the distributed version control system is much higher , because everyone’s computer has a complete version library. It doesn’t matter if a personal computer is broken, just copy one from others. That's it.
And if there is a problem with the central server of the centralized version control system, everyone will be unable to work.

When actually using a distributed version control system, you rarely push revisions to the repository on the computer between the two, because maybe you two are not in the same local area network and the two computers can’t access each other, or your colleague today He was sick, and his computer didn't turn on at all. Therefore, a distributed version control system usually also has a computer that acts as a "central server", but the role of this server is only to facilitate the "exchange" of everyone's modifications. Without it, everyone can work the same, but it is inconvenient to exchange and modify. .

Insert picture description here
Of course, the advantage of Git is not only that it does not need to be connected to the Internet. Later we will see Git's extremely powerful branch management, leaving SVN and so on far behind.

As the earliest open source and free centralized version control system, CVS is still used by many people. Due to the problem of CVS's own design, the submitted files will be incomplete and the repository will be damaged inexplicably. SVN, which is also open source and free, has corrected some stability issues of CVS, and is currently the most used centralized version library control system.

In addition to free of charge, there are also paid centralized version control systems, such as IBM's ClearCase (formerly owned by Rational and acquired by IBM), which is characterized by larger installation than Windows, slower operation than snails, and ClearCase They are generally the Fortune Global 500, and they have a common feature of having a lot of money, or stupid people and a lot of money.

Microsoft itself also has a centralized version control system called VSS, which is integrated in Visual Studio. Because of its anti-human design, even Microsoft itself is embarrassed to use it.

In addition to Git and BitKeeper that led to the birth of Git, distributed version control systems also include Mercurial and Bazaar similar to Git. These distributed version control systems have their own characteristics, but the fastest, easiest and most popular is still Git!

Guess you like

Origin blog.csdn.net/qq_28258885/article/details/114973540