Chapter 7 Version Controller - git

1. The history of git

The founder of git is Linus Torvalds. Some people may think that this name sounds familiar. Yes, Linus Torvalds is the founder of linux. We mentioned this great person in the first chapter of the linux column.
Linus Torvalds (picture from the Internet)

In 2005, linux became more and more popular among developers, and more and more developers submitted codes about updating the linux kernel to Linus Torvalds. With more and more contributions, the linux kernel is becoming more and more perfect, but at the same time a serious problem has emerged: the version management problem. Each update represents an iteration of the version. With more iterations, the differences between versions gradually blur in Linus Torvalds' mind. At this time, Linus Torvalds urgently needs a version management tool.

When Linus Torvalds had this need, he began to look for version management tools on the market. Finally, Linus Torvalds found a paid version management tool: BitKeeper (BK). Since Larry McVoy, the founder of BK, is a fan of linux, he said that BitKeeper is provided free of charge to linux developers. After using it for a period of time, a linux developer tried to crack BitKeeper, which made BitKeeper very dissatisfied. Therefore, BitKeeper terminated the free use right of linux developers.

After the right to use was terminated, the founder of Linux summed up some advantages and disadvantages of BitKeeper, and at the same time combined some of his own ideas. Linus Torvalds wrote an open source version management software - git in about ten days. That's where git came from, but it didn't stop there. So far, git can be said to have become the most popular version management software in the world.

2. The characteristics and development of git

1. Features of git

Before the creation of git, most version management tools were almost all centralized version control systems. This type of system has a server with a single version centralized management, and all versions are saved on the server. The relevant developers will connect to this server through the client, and then take out the latest file version or submit their own updates. But there is a big problem with this approach. If there is a problem with the central server, all developers will not be able to download the latest code version from the server. In addition, if the central server is damaged, this may lead to the loss of code versions. Since only this server has all the code versions, once it is lost, there will be no backup to restore it. To sum up, this version management system is very risky.

Git uses a distributed version management system. Developers don't just pull the latest code version. Instead, the entire image of the code warehouse is copied, so that each developer has a complete code backup on his computer. If something happens to a developer's computer, it will not affect the development progress of other developers. At the same time, if the code is lost, other developers can also use the complete mirror warehouse to repair it.

2. git and github

The author believes that many programmers have heard of the github website. But most people don't know the difference between git and github. Through the above introduction, we can actually make a summary of git. Git is a software that can mirror the remote code warehouse to the local. And github is a website, this website is a free code hosting warehouse. That is, our code allows the github website to help us host various versions of the code. The two cooperate with each other. If you use school as a metaphor, home is local, school is github, transportation is git, and people can be compared to code. We can realize the flow of students between home (local) and school (github) through the transportation tool git.
insert image description here

2. Installation and registration of git

1. Git installation

Here we take Ubuntu's linux as an example.

sudo apt install git

2. Use of git

If we want to use git, we must have a hosting platform to record our code. Then the platform we choose here is gitee. Since github is a foreign website, the access speed is slightly slower. If you can’t surf the Internet scientifically, You can use the domestic code hosting platform: gitee (code cloud). There is another reason why the author chooses Code Cloud here. Sometimes even if you can surf the Internet scientifically, github often has some network errors when cloning and pushing.

(1) github registration

First, we register an account of our own on the website gitee .

(2) Create a remote warehouse

insert image description here

insert image description here

insert image description here
After the creation is successful, you can find the link corresponding to this warehouse. The function of this link is to facilitate us to copy the mirror image of the remote warehouse to the local.

(3) Copy the remote warehouse image to the local warehouse

instruction

git clone 仓库链接

example

insert image description here
It should be noted here that when we use it for the first time, we will be asked to enter the username and password of gitee.

(4)git add

instruction

First, we first enter the local mirror warehouse, and then copy or cut the files we want to add to the warehouse. But at this time, the code we pasted directly is not managed by the git software. Therefore, we need to tell the git software the code we want to add through the following instructions.

git add [文件名]

The file name here can be written directly ., .which means the current directory, that is, in the warehouse. So git will manage the files in the warehouse that are not managed by git.

example

insert image description here

(5)git commit

Git add is to submit the code to the temporary storage area. The concept of the temporary storage area will not be described in detail here. git commit is to submit the code to the branch. The two seem to have similar functions on the surface, but in fact there are still differences.

instruction

git commit -m "代码日志(可以写你修改了什么内容)"

example

insert image description here

(6)git push

Synchronize the local warehouse to the remote warehouse. The first submission may require a user name and password.

instruction

git push

example

insert image description here
At this point we can see the code we submitted on Code Cloud. As shown in the figure below:
insert image description here
the function of the instructions introduced above is to submit your own code to the remote warehouse.
To sum up: the process is: git clone --> 代码复制到仓库 --> git add . --> git commit -->git push
In addition, we can also view some information of the warehouse through some instructions.

(7)git log

After we copy the warehouse to the local, we can view the submission log of the warehouse through the following command.

instruction

git log

example

insert image description here

(8)git rm

We can not only add files, but also delete some files. After deleting: git add --> git commit --> git push, the remote warehouse will delete the corresponding file.

instruction

git rm 文件名

example

insert image description here

(9) git status

View the synchronization status of the remote warehouse and the local warehouse

instruction

git status

example

insert image description here

Guess you like

Origin blog.csdn.net/weixin_72060925/article/details/131503706