The role and simple use of git

You may have heard of github, but you may not know what git is? Some people may think that git is not very useful. You can download open source projects and so on directly by operating on the graphical interface. It is simple and convenient, and there is no need to use the git clone command at all. But the role of git is far greater than imagined. The following learning is based on the experience summarized in the tutorials of teacher Liao Xuefeng.

1. What is git?
Git is a distributed version control system. To put it simply, it is to help you manage your project. It can automatically record what changes are made to your project every time and who made the changes. This avoids manual management by yourself. If we make one or two changes, we can manage it ourselves, but a large project at work needs to be changed many times, and is completed by many people, so manual management will be time-consuming, labor-intensive, and errors may occur.
Regarding centralized mode, that is, after your project is written, it will be submitted to the central server, and the next time you continue to write, it will be transferred from the server. This is a test for the network speed, and "a little paralysis will cause everyone to take a vacation." In distributed mode, each host has its own version library and does not need to be connected to the Internet.
2. The birth of git
First of all, everyone knows a little about the concept of distribution, so there used to be centralized version control software such as svn and cvs. However, it is slow and requires networking. Other distributed commercial management systems require fees, which is not in line with the open source concept.
We know that after the father of Linux wrote Linux, because it was open source, enthusiasts all over the world contributed code to him. However, the increasingly large code base was too difficult to manage manually, so he wrote another one. Version control system----Git. And it took two weeks to write it.

3.git installation
Here I only introduce the installation of git under windows.
First, you need to download it from the official website. It is very simple and can be installed by default.
After the installation is complete, the last step of setting is required. Enter on the command line:
$ git config --global user.name "Your Name"
$ ​​git config --global user.email "[email protected]"
because Git is a distributed version Control system, therefore, each machine must report itself: your name and email address.
To check whether the setting is successful, you can use git config user.name and the name you set will appear.

4. Create a version library.
What is a version library? The version library is also known as the warehouse, and the English name is repository. You can simply understand it as a directory. All files in this directory can be managed by Git. Git can track the modification and deletion of each file, so that it can be tracked at any time. History, or can be "restored" at some point in the future.

Many of the commands here require basic Linux commands. You can read my Linux basics column.
$ mkdir learngit
$ cd learngit
$ pwd
creates an empty directory and moves it to this directory, and then
git init turns this directory into a git-managed warehouse.
We test submitting the file to the warehouse:
use the touch file name to create a new file, and then use the vi file name to edit the file. We need to know how to use the three modes of the vi editor. (The file must be built in this directory)
Submitting the file to the warehouse only requires two steps:
then git add file name tells git to add this file to the warehouse
git commit -m "your modification prompt information"

Why is there commit? Because commit can submit multiple files at one time. We can add multiple ones and commit them once.
At this point, you have created the warehouse and submitted a file.

In the next article, we will talk about how to roll back, undo, modify and other operations. At this point you will find that git is superior to the graphical interface on github.

Guess you like

Origin blog.csdn.net/weixin_53344209/article/details/115701814