Git version control tool - background introduction (1)

1. What is Git?

Version control tool! Git is currently the most advanced distributed version control system in the world (one of the few).

This software should be used like this, recording every file change.
Insert image description here
In this way, you have ended the prehistoric era of manually managing multiple "versions" and entered the 20th century of version control.

2. Git development history

cvs --svn

Before 2002, volunteers from all over the world sent source code files to Linus through diff, and then Linus himself merged the code manually! You may be thinking, why doesn't Linus put the Linux code into the version control system? Aren’t there free version control systems like CVS and SVN? Because Linus firmly opposes CVS and SVN, these centralized version control systems are not only slow, but also require an Internet connection to be used. There are some commercial version control systems. Although they are easier to use than CVS and SVN, they are paid and inconsistent with the open source spirit of Linux.

Linus spent two weeks writing a distributed version control system in C. This is Git! Within a month, the source code of the Linux system has been managed by Git! Git quickly became the most popular distributed version control system. Especially in 2008, the GitHub website was launched, which provided free Git storage for open source projects. Countless open source projects began to migrate to GitHub, including jQuery, PHP, Ruby, etc.

3. How Git runs

1. Centralized VS distributed

CVS and SVN, which Linus has always hated, are centralized version control systems, while Git is distributed version control.

1) Centralized version control system

The version library is stored in a centralized server. When you work, you use your own computer, so you must first obtain the latest version from the central server, then start working, and then upload your own work after finishing the work. Pushed to central server. The central server is like a library. If you want to modify a book, you must first borrow it from the library, then go home and modify it yourself. After modifying it, put it back into the library. The biggest disadvantage of a centralized version control system is that it must be connected to the Internet to work. If it is in a local area network, it is fine and the speed is fast enough. But if it is on the Internet and the network speed is slow, it may take 5 minutes to submit a 10M file. This You can't even suffocate people to death.

2) Distributed version control system

There is no "central server" at all. Everyone's computer has 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 every computer has a complete version library, 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 only need to push your modifications to each other, and you can see each other's changes. edited. Compared with the centralized version control system, the security of the distributed version control system is much better, because each computer has a complete version library, it does not matter if someone's computer is broken, and the central server of the centralized version control system If something goes wrong, no one can work

The running method of git is as shown in the figure
Insert image description here

2. Work area and temporary storage area

One difference between Git and other version control systems such as SVN is the concept of staging area and workspace;
Working Directory : the directory you can see on your computer,
Repository : working area There is a hidden directory ".git". This is not a workspace, but the Git version library. The Git version stores many things, the most important of which is called stage (Or index) , as well as the first branch master that Git actively created for us, and a pointer to master called HEAD.
When we add files to the Git repository, we do it in two steps:

The first step is to use "git add" to add the file, which is actually to add the file modifications to the temporary storage area; the
second step is to use "git commit" to submit the changes, which is actually to submit all the contents of the temporary storage area to Current branch. Because when we created the Git repository, Git actively created the only master branch for us, so now commit means submitting changes to the master branch. You can simply understand that all file modifications that need to be submitted are placed in the temporary storage area, and then all modifications in the temporary storage area are submitted at once.

4. Commonly used Git servers

1) github - the world's largest open source website
2) Code Cloud - free, domestic
3) coding——domestic

5. Install Git

1. Installation in window
Download and install the client. If the installation is successful, check whether the installation is successful.

Method 1 : Right-click the mouse on the desktop to display git bash here.
Enter git --version in the interface to display the version.

Method 2 : Run cmd and enter git --version to display the version

2. Install Git on Linux system
Method 1: yum installation

yum search Git===Check if there is git and download it if so

Git --version====Check version

Download the latest version official website: git-scm.com

Note: By default, yum install git installs git 1.7.1 version
coding. The git version to be used is 1.8.0 or above, and there is an error when cloning this version, so you need to install git manually.

Method 2: Manually install git
1、安装git依赖包
	yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
2、删除已有的git
	yum remove git
3、下载git源码
	wget https://www.kernel.org/pub/software/scm/git/git-2.8.3.tar.gz 
	tar -zxvf git-2.8.3.tar.gz
	cd git-2.8.3
	./configure prefix=/usr/local/git/
	make && make install
4、将git指令添加到bash中,添加到环境变量中
	vi /etc/bashrc
	在最后一行介入
	export PATH=$PATH:/usr/local/git/bin
	source /etc/bashrc  即可
	git --version   git已经安装好,可以查看git版本

6. Git operation (take Github website as an example)

1. Register and log in to the Github website

Regular registration, please note that email authentication is required, otherwise the project cannot be created

2. Create a warehouse on Github

Create a new repository (Repositories), fill in the project name and project description, and a URL will be generated if the creation is successful.

3. Get the project—get the project from the server (cloud) to the local

Find a folder locally to store the files, then right-click to open git and execute the following code. You can get your own or other people's projects locally.

git clone https地址====将仓库克隆到本地

Note: [Create ssh key] can also be created before

The purpose of creation is to ensure security. Only administrators with keys can upload, others can only download.

Enter the command in git to generate the key ===ssh-keygen, generate the private key id_rsa and the public key id_rsa.pub

Paste the public key into the website
Insert image description here
Insert image description here

4. Drop down items to update local

See the latest code of the server locally (update modifications)

git pull    ====  从服务器更新代码
5. Push locally to the server

First implement version control locally, that is, create a version library, also called a repository.

(1) Create a warehouse (version library), choose a suitable location and create an empty directory
mkdir +文件名     #文件名和路用英文,文件编辑可用notepad++
cd 文件名
(2) Enter the target folder (the folder where the file you want to push is located)
git init    初始化Git仓库,将这个目录可以变为仓库
git add +文件名    添加指定文件
(或者git add .     添加所有文件)

git status  查看当前状态
(3) Submit documents
git  commit  -m  "我写的内容原因"   
(注意:提交原因必须写,否则不能推送)
(4) Push files to the server
git push 
或者git push origin(服务器项目默认名字) master

reference:

Git version control (perfectly organized version)

Distributed version control tool—Git

Guess you like

Origin blog.csdn.net/qq_42886163/article/details/102596032