Git developers to easily grasp the basic concepts (a) Introduction

In the last year, when I would have written a tutorial column Git, but Git is still relatively small at that time for contact, the article may also be written is not precise enough is not good enough, so I'm going to re-write a column Git, this time I will try to Git knowledge of all aspects are introduced to try to put it easy to understand, I want to be able to help you want to learn Git's.

Git Introduction

First to talk about Git, I believe we no stranger to Git, it is an open source distributed version control system that can efficiently at high speed process from small to very large project version management, a concept involved here: Version control.
So what is the version control? Why do you need version control it?

Give you an example, like you're doing a resume recently, hard to do one afternoon, the general structure has been done. The next day, you suddenly think of some place on a resume is not very reasonable, so you turn on the computer going to change, you can not directly modify the thought based on the original, otherwise the case could not be changed tune and wanted to go back on the easy ones, and this when your mind there is the thought of a version control.

The results changed for several days, more and more versions of your resume:
Here Insert Picture Description
you start to feel that this is not a good way, then there is no such a tool can record every version of my resume, and I modify the contents of the next record, and can freely I want to switch to resume version of it? Yes, of course, Git can help you achieve.

In fact, Git's capabilities than that, it has the following features:

  1. Collaborative modification
  2. data backup
  3. Version Management
  4. Access control
  5. history record
  6. Branch Management

Another version control system introduced

About version control tools, can be divided into two categories, one is SVN is centralized version control tools on behalf of the working principle of such tools is: it has a central server, all developers need to download it from the server code to the local and then developed locally, after the completion of the development submitted to the server.

So the biggest drawback of centralized version control tool is that it can not be away from the server, if the damage to the server, all files will be lost.

Another type is the representative of the Git distributed version control tools, such tools for each developer, it can be controlled directly in the local version, that is to say, there is complete submission local history. This class tool does not limit the central server, which greatly reduces the possibility of missing files.

Git development history

The simple mention it, I believe these historical stories we all familiar with the.

Git is the creator Linus Torvalds, Linux produce Git not leave the system, we know that Linux creator Linus Torvalds is the system, this is a legend, it has a classic saying: Talk is cheap, show me the code-- can not really say anything, have the ability to put your code to me.

The original Linux system is composed of Linus I am responsible merge code cattle people from around the world offered, but with the growing system, code is increasingly used to manually merge apparently too much work. This time BitKeeper software company BitMover owner of the software is free for humanitarian licensed to use the Linux open source community, but the community was trying to hack Linux BitKeeper software, resulting in BitMover companies to recover the free use rights. Of course, which we are unable to judge right or wrong, it is said BitMover's licensing terms, there are many on the Linux developer community is very unequal treaties.

Things always happen, no way, Linus once again play to their strength program, within two weeks with the C language has developed a Git's main program, one month after the Linux system code has been handed over to Git managed.

Download and install Git

In order to take care of students did not Linux-based (In fact, I also less likely Linux command), all subsequent operations will operate on a Windows system, we first official website to download Git good, Download: HTTPS: // GIT- scm.com/downloads

According to their needs download the appropriate version, the download is complete, double-click to open the installation package to start installation:
Here Insert Picture Description
direct the next step here:
Here Insert Picture Description
here is also directly next step on it:
Here Insert Picture Description
still direct the next step:
Here Insert Picture Description
It should be noted, the installation program is selected by default second, we explain each of these three cases:

  1. The first way is not to modify the system variable PATH, which is a security best practice, but can only use Git Git Bash instruction in
  2. The second way would be to modify the system variable PATH, so that you can use Git command in the Windows CMD window, but this is only a theory security practices, it does not guarantee absolute safety
  3. 第三种方式也会去修改系统变量PATH,而且会覆盖find和sort命令,

所以这里我们可以视情况选择第一种或者第二种方式,千万不要选第三种,我推荐大家选择第一种方式就足够了,选择好后点击下一步:
Here Insert Picture Description
这里是选择本地库和远程库的连接方式,默认即可,下一步:
Here Insert Picture Description
这里是对Windows和Unix之间的回车换行符风格进行一个转换,默认即可,下一步:
Here Insert Picture Description
这里选择使用哪个终端,默认即可,下一步:
Here Insert Picture Description
这里同样默认即可,然后点击Install进行安装,这样Git就安装完成了。

此时我们只需要在任何位置右键鼠标,就会出现如下两个选项:
Here Insert Picture Description
点击Git Bash Here就能够打开Git的终端:
Here Insert Picture Description

代码托管中心

通过前面的了解,我们知道,Git使得每位开发人员能够在本地进行版本的迭代,那么代码托管中心的作用是什么呢?

它的作用是维护远程库,典型的代码托管中心有:GitHub和码云。

在局域网内,我们也可以通过GitLab自己搭建一个托管中心。

本地库与远程库的交互

下面介绍一下本地库与远程库的交互操作,具体分为两种情况:

  1. 团队内部协作
  2. 跨团队协作

团队内部协作

先说说团队内容协作,假设有一个程序员张三,它手下有一个员工李四,这两个人如何进行团队协同开发呢?

首先张三在自己本地进行开发,将项目的基本结构搭建好,此时张三将本地库的代码推送到远程库:
Here Insert Picture Description
这时候托管中心就有了张三推送上去的远程库,此时李四只需要将远程库的代码下载到本地即可:
Here Insert Picture Description
这样李四也在本地进行开发,开发完成后将本地库推送到远程库即可:
Here Insert Picture Description
李四对远程库进行了修改之后,张三要想获得李四的修改内容,就需要对远程库进行一个拉取的操作,将远程库的内容拉取到本地库:
Here Insert Picture Description
这样两个人便实现了协同开发,注意这里的李四并不能直接将本地库的代码推送到远程库,因为这个远程库是张三创建的,李四要想推送代码,就必须加入到张三的项目团队中,这个后面会具体介绍。

跨团队协作

再假设一种情况,有一个程序员老汪正在进行项目开发,发现自己遇到了一个难题,于是它找到了以前的师傅老魏,请求它帮忙,但是老魏不是这个项目团队的人,此时老汪将自己本地的代码推送到了远程库:
Here Insert Picture Description
老魏要想参与到项目中,就需要将老汪推送的远程库作一个复制的操作:
Here Insert Picture Description
此时代码托管中心就有了两份一模一样的远程库,只不过一份是老汪的,一份是老魏的,接着老魏将自己远程库的代码克隆到本地库:
Here Insert Picture Description
老魏就可以进行开发了,问题解决后,老魏将本地库的代码推送到自己的远程库:
Here Insert Picture Description
但这时候改变的仅仅是老魏的远程库,老汪的远程库并没有被修改,这时候老魏需要发起一个pull request,发起请求后,老汪就会收到老魏的请求和代码,经过老汪审核后,就可以合并到自己的远程库中:
Here Insert Picture Description
此时老汪再对远程库进行拉取操作,就可以将老魏修改的代码获取到本地了。

Published 107 original articles · won praise 8979 · Views 660,000 +

Guess you like

Origin blog.csdn.net/qq_42453117/article/details/104277391