Git是什么?

Git是目前世界上最先进的分布式版本控制系统(没有之一)。另外,Git极其强大的分支管理,把SVN等远远抛在了后面。
项目源码由Git管理,而GitHub和码云都是基于Git的开源项目托管平台,它为开源项目免费提供Git存储。

 

重要参考:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

 

目的:本文重点介绍Linux环境下安装git工具,与简单使用git管理本地仓库的方法。


系统环境

[hinzer@VM_16_8_centos learngit]$ uname -a
Linux VM_16_8_centos 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux


Linux系统上安装Git工具

1.查看Linux系统上有无安装git,我这显然没有安装过git

[hinzer@VM_16_8_centos ~]$ git
-bash: git: command not found


2.安装git工具

[hinzer@VM_16_8_centos ~]$ sudo yum install -y git

3.声明自己的昵称和邮箱

[hinzer@VM_16_8_centos learngit]$ git config --global user.name "Your Name"
[hinzer@VM_16_8_centos learngit]$ git config --global user.email "email@example.com"

 

创建版本库

也就是本地仓库,用于本机进行项目代码的管理

1.创建目录

[hinzer@VM_16_8_centos ~]$ mkdir learngit
[hinzer@VM_16_8_centos ~]$ cd learngit/
[hinzer@VM_16_8_centos learngit]$ pwd
/home/hinzer/learngit

2.生成git仓库

[hinzer@VM_16_8_centos learngit]$ git init
Initialized empty Git repository in /home/hinzer/learngit/.git/
[hinzer@VM_16_8_centos learngit]$ ls -a
.  ..  .git

 


简单使用

1.告诉git要添加的文件

[hinzer@VM_16_8_centos learngit]$ touch readme.txt
[hinzer@VM_16_8_centos learngit]$ echo "Git is a version control system." &> readme.txt

2.把文件提交到本地仓库

[hinzer@VM_16_8_centos learngit]$ git add readme.txt
[hinzer@VM_16_8_centos learngit]$ git commit -m "wrote a readme file"          
[master (root-commit) 643fefe] wrote a readme file
 1 file changed, 1 insertion(+)
 create mode 100644 readme.txt

 -m 参数后面是对提交的一些说明。也可以多次add添加,一次commit提交.