Git介绍、安装

Git介绍、安装

Git介绍

Git的历史

​ 同生活中的许多伟大事件一样,Git 诞生于一个极富纷争大举创新的年代。Linux内核开源项目有着为数众广的参与者。绝大多数的 Linux内核维护工作都花在了提交补丁和保存归档的繁琐事务上(1991-2002年间)。到 2002 年,Linux系统已经发展了十年了,代码库之大让Linus很难继续通过手工方式管理了,于是整个项目组开始启用分布式版本控制系统 BitKeeper 来管理和维护代码。

​ 到 2005 年的时候,开发 BitKeeper 的商业公司同 Linux 内核开源社区的合作关系结束,他们收回了免费使用 BitKeeper 的权力。这就迫使 Linux 开源社区(特别是Linux的缔造者 Linus Torvalds )不得不吸取教训,只有开发一套属于自己的版本控制系统才不至于重蹈覆辙。他们对新的系统订了若干目标:

  • 速度
  • 简单的设计
  • 对非线性开发模式的强力支持(允许成千上万个并行的开发分支)
  • 完全分布式
  • 有强大高效管理类似Linux内核一样的超大规模项目(速度和数据量)

Git是什么

​ Git是一款免费的、开源的分布式版本控制系统,用于敏捷高效地处理任何或大或小的项目。

​ Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。Git 是 Linus Torvalds 为了帮助管理Linux内核开发而开发的一个开放源码的版本控制软件。

官网:https://git-scm.com/

Git的特点

  • 优点:
    • 适合分布式开发,强调个体;
    • 公共服务器压力和数据量都不会太大;
    • 速度快、灵活;
    • 任意两个开发者之间可以很容易解决冲突;
    • 离线工作。
  • 缺点:
    • 代码保密性差,一旦开发者把整个库克隆下来就可以完全公开所有代码和版本信息;
    • 权限控制不友好。

Git工作流程

一般工作流程如下:

  1. 从远程仓库中可怜Git资源作为本地仓库;
  2. 从本地仓库中chekout代码然后进行代码修改;
  3. 在提交本地仓库前先将代码提交到暂存区;
  4. 修改提交,提交到本地仓库;本地仓库中保存修改的各个历史版本;
  5. 在需要和团队成员共享代码时,可以将本地仓库中的代码push带服务器代码仓库。

Git工作流程图:

在这里插入图片描述

Git几个核心概念

工作区、暂存区、版本库、远程仓库

在这里插入图片描述

WorkSpace:工作区,平时存放项目代码的地方

Index\Stage:暂存区,用于临时存放你的改动,事实上它只是一个文件,保存即将提交到文件列表信息

Repository:仓库区(或版本库),就是安全存放数据的位置,这里面有你提交到所有版本的数据。其中HEAD指向最新放入仓库的版本

Remote: 远程仓库,托管代码的服务器,可以简单的认为是你项目组中的一台电脑用于远程数据交换

分支

​ 每次的提交Git都把它们串成一条时间线,这条时间线就是一个分支。截止到目前,只有一条时间线,在Git里这个分支叫主分支,即master分支。HEAD指针严格来说不是指向提交,而是指向master,master才是指向提交的。


Git安装

Windows安装

1、Git下载

到官网下载,

官网:https://git-scm.com/ (不同系统不同平台的安装包和源代码)

Windows平台:https://gitforwindows.org/ (只有 windows 系统的安装包)

2.1、选择目录

默认安装路径为:C:\Program Files\Git,修改需要安装的目录。

在这里插入图片描述

2.2、选择安装组件

对应组件翻译如图

在这里插入图片描述

2.3、选择Git默认编辑器

Git 安装程序里面内置了 10 种编辑器供你挑选,比如 AtomNotepadNotepad++Sublime TextVisual Studio CodeVim 等等,默认的是 Vim,选择 Vim 后可以直接进行到下一步,但是 Vim 是纯命令行,操作有点难度,需要学习。如果选其他编辑器,则还需要去其官网安装后才能进行下一步。

在这里插入图片描述

2.4、调整Path环境变量

在这里插入图片描述

翻译如下:

Use Git from Git Bash only 
This is the most cautious choice as your PATH will not be modified at all. You w only be able to use the Git command line tools from Git Bash.
仅从 Git Bash 使用 Git
这是最谨慎的选择,因为您的 PATH 根本不会被修改。您将只能使用 Git Bash 中的 Git 命令行工具。


Git from the command line and also from 3rd-party software
(Recommended) This option adds only some minimal Git wrappers to your PATH to avoid cluttering your environment with optional Unix tools.
You will be able to use Git from Git Bash, the Command Prompt and the Windov PowerShell as well as any third-party software looking for Git in PATH.
从命令行以及第三方软件进行 Git
(推荐)此选项仅将一些最小的 Git 包装器添加到PATH中,以避免使用可选的 Unix 工具使环境混乱。
您将能够使用 Git Bash 中的 Git,命令提示符和 Windov PowerShell 以及在 PATH 中寻找 Git 的任何第三方软件。


Use Git and optional Unix tools from the Command Prompt 
Both Git and the optional Unix tools will be added to your PATH.
Warning: This will override Windows tools like "find"and "sort". Only use this option if you understand the implications.
使用命令提示符中的 Git 和可选的 Unix 工具
Git 和可选的 Unix 工具都将添加到您的 PATH 中。
警告:这将覆盖 Windows 工具,例如 "find" and "sort". 仅在了解其含义后使用此选项。

​ 第一种是仅从Git Bash使用Git。这个的意思就是你只能通过 Git 安装后的 Git Bash 来使用 Git ,其他的什么命令提示符啊等第三方软件都不行。

​ 第二种是从命令行以及第三方软件进行 Git。这个就是在第一种基础上进行第三方支持,你将能够从 Git Bash命令提示符(cmd)Windows PowerShell 以及可以从 Windows 系统环境变量中寻找 Git 的任何第三方软件中使用 Git。

​ 第三种是从命令提示符使用 Git 和可选的 Unix 工具

2.5、选择SSH执行文件

在这里插入图片描述

翻译:

Use bundled OpenSSH 
This uses ssh. exe that comes with Git.
使用捆绑的 OpenSSH
这使用的 ssh.exe 是 Git 自带的 


Use (Tortoise) Plink 
To use PuTTY, specify the path to an existing copy of (Tortoise) Plink.exe
Set ssh. variant for Tortoise Plink 
使用 TortoisePlink (注,这是一个软件)
要使用 PuTTY,请指定 TortoisePlink.exe 的现有副本的路径
为 TortoisePlink 设置 ssh.variant

2.6、选择HTTPS后端传输

在这里插入图片描述

翻译:

use the OpenSSL library 
Server certificates will be validated using the ca-bundle. crt file.
使用 OpenSSL 库
服务器证书将使用 ca-bundle.crt 文件进行验证。
	
Use the native Windows Secure Channel library 
Server certificates will be validated using Windows Certificate Stores.
This option also allows you to use your company's internal Root CA certificates distributed e.g. via Active Directory Domain Services.
使用本机 Windows 安全通道库
服务器证书将使用 Windows 证书存储进行验证。
此选项还允许您使用公司内部分发的内部根 CA 证书,例如通过 Active Directory 域服务。

2.7、配置行尾符号转换

在这里插入图片描述

翻译:

Checkout Windows-style, commit Unix-style line endings 
Git will convert LF to CRLF when checking out text files. 
When committing text files, CRLF will be converted to LF. For cross-platform projects, this is the recommended setting on Windows("core. autocrif"is set to "true").
签出 Windows 样式,提交 Unix 样式的行结尾
Git 签出文本文件时,会将 LF 转换为 CRLF。
提交文本文件时,CRLF 将转换为 LF。
对于跨平台项目,这是 Windows 上的建议设置("core.autocrif" 设置为 "true")。

Checkout as-is, commit Unix-style line endings 
Git will not perform any conversion when checking out text files. 
When committing text files, CRLF will be converted to LF. For cross-platform projects, this is the recommended setting on Unix("core.autocrif" is set to "input").
按原样签出,提交 Unix 样式的行结尾
Git 在签出文本文件时不会执行任何转换。提交文本文件时,CRLF 将转换为 LF。
对于跨平台项目,这是在 Unix 上的建议设置("core.autocrif" 设置为 "input")。

Checkout as-is, commit as-is 
Git will not perform any conversions when checking out or committing text files. 
Choosing this option is not recommended for cross-platform projects("core. autocrif"is set to "false").
按原样签出,按原样提交
Git 在签出或提交文本文件时不会执行任何转换。
不建议跨平台项目选择此选项("core.autocrif" 设置为 "false")。

2.8、END

​ 往后一直默认下一步就完成了。


Linux安装

​ 以Centos7为例:

1、安装环境

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y
yum install gcc-c++ perl-ExtUtils-MakeMaker autoconf -y

2、从GitHub上下载Git

wget https://github.com/git/git/archive/v2.27.0.tar.gz

3、解压并进入目录

tar -zxvf v2.27.0.tar.gz
cd git-2.27.0/

4、配置

make configure
./configure --prefix=/usr/local/git

5、编译

make prefix=/usr/local/git

6、安装

make install

7、配置环境变量并使环境变量生效

echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/profile
source /etc/profile

8、查看Git是否安装成功

git --version

t


#### 5、编译

make prefix=/usr/local/git


#### 6、安装

make install


#### 7、配置环境变量并使环境变量生效

echo ‘export PATH=$PATH:/usr/local/git/bin’ >> /etc/profile
source /etc/profile


#### 8、查看Git是否安装成功

git --version


​	在窗口当中出现Git的版本号,则说明安装成功。

猜你喜欢

转载自blog.csdn.net/weixin_44030265/article/details/128289594