1、简介

linus 用C语言编写
2005年诞生
分布式版本管理系统
速度快,适合大规模,跨地区多人协同开发

2、分布式

3、Git 生态

Git 分布式版本管理系统
Gitlab git私库解决方案
Github git公有库解决方案

4、Git安装

4.1、快速安装

Centos:
yum install git

Ubuntu:
apt-get install git

Windows安装git bash

4.2、编译安装

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

wget https://github.com/git/git/archive/v2.7.4.zip
unzip v2.7.4.zip
cd git-2.7.4

make prefix=/usr/local/git all
make prefix=/usr/local/git install
rm -rf /usr/bin/git
ln -s /usr/local/git/bin/git /usr/bin/git
git --version

注意:Liunx编译安装,不要使用git1.8以下版本,推荐使用2.7版本

5、Git命令

设置与配置

git config

帮助命令

git help

初始化

git init
git config --global user.name "liyanzhao"
git config --global user.email 1210353303@qq.com
#git config --global color.ui true

检查git相关配置

git config --list

获取

git clone http://xxx.git

6、四个区域

7、四种状态

8、案例演示

开发一个首页文件,news页面,支付页面

查看提交的日志

[root@linux-node5 test]# git log    # 查看提交的日志
fatal: your current branch 'master' does not have any commits yet

查看工作区和暂存区的状态

[root@linux-node5 test]# git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

开发一个首页文件

[root@linux-node5 test]# echo "111" > index.html

可以看到未被追踪的文件

[root@linux-node5 test]# git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    index.html    # 工作区

nothing added to commit but untracked files present (use "git add" to track)

加入暂存区

[root@linux-node5 test]# git add index.html
[root@linux-node5 test]# git status   #查看状态
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)   

    new file:   index.html

提交到本地仓库

[root@linux-node5 test]# git commit -m "first commit"
[master (root-commit) aa802c2] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
[root@linux-node5 test]# git status
On branch master
nothing to commit, working directory clean
[root@linux-node5 test]# git log   #查看日志
commit aa802c2fe39d27c11eba7e9659b12b32a2fe2304
Author: liyanzhao <1210353303@qq.com>
Date:   Thu Mar 28 16:27:13 2019 +0800

    first commit

开发支付模块,并提交至暂存区

[root@linux-node5 test]# touch pay.html
[root@linux-node5 test]# git add pay.html
[root@linux-node5 test]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   pay.html

[root@linux-node5 test]# echo "news" >> news.html
[root@linux-node5 test]# git add news.html
[root@linux-node5 test]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   news.html
    new file:   pay.html

pay从暂存区回滚之工作区

[root@linux-node5 test]# git rm --cached pay.html    # 提示 git rm --cached <file> 可以把文件从暂存区移除,回到工作区。
rm 'pay.html'
[root@linux-node5 test]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   news.html

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    pay.html

提交news,修改pay再次提交

[root@linux-node5 test]# git commit -m "news"
[master 0510d3d] news
 1 file changed, 1 insertion(+)
 create mode 100644 news.html
[root@linux-node5 test]# git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    pay.html

nothing added to commit but untracked files present (use "git add" to track)
[root@linux-node5 test]# git log
commit 0510d3d204d4f3f770927e98d8d17688e27cb61b
Author: liyanzhao <1210353303@qq.com>
Date:   Thu Mar 28 16:31:40 2019 +0800

    news

commit aa802c2fe39d27c11eba7e9659b12b32a2fe2304
Author: liyanzhao <1210353303@qq.com>
Date:   Thu Mar 28 16:27:13 2019 +0800

    first commit
[root@linux-node5 test]# echo "ppppp" >> pay.html
[root@linux-node5 test]# echo "plll" >> pay.html
[root@linux-node5 test]# git add pay.html
[root@linux-node5 test]# git commit -m "pay"
[master 6ab971b] pay
 1 file changed, 2 insertions(+)
 create mode 100644 pay.html
[root@linux-node5 test]# git log
commit 6ab971b1f4679b213a05749f4aceb844ffe2d29a
Author: liyanzhao <1210353303@qq.com>
Date:   Thu Mar 28 16:33:05 2019 +0800

    pay

commit 0510d3d204d4f3f770927e98d8d17688e27cb61b
Author: liyanzhao <1210353303@qq.com>
Date:   Thu Mar 28 16:31:40 2019 +0800

    news

commit aa802c2fe39d27c11eba7e9659b12b32a2fe2304
Author: liyanzhao <1210353303@qq.com>
Date:   Thu Mar 28 16:27:13 2019 +0800

    first commit

9、常用命令

git add         加入暂存(索引区)
git status         查看状态
git status -s    状态概览
git diff        尚未暂存的文件
git diff --staged    暂存区文件
git commit     提交更新
git reset         回滚
git rm         从版本库中移除
git rm --cached README 从暂存区中移除
git mv         相当于mv git rm git add三个命令
文档更新时间: 2019-03-28 18:09   作者:李延召