git安装与创建版本库

安装git:

安装git依赖

[root@manager ~]# yum update -y

[root@manager ~]yum install unzip curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker -y

[root@manager ~]yum install git -y

创建版本库:

# 第一步:创建版本库
[root@manager ~]# mkdir /source
[root@manager ~]# cd /source
[root@manager source]# git init
Initialized empty Git repository in /source/.git/
[root@manager source]# ls -a
.  ..  .git

# 指定当前操作的用户的用户名和邮箱
[root@manager source]# git config --global user.email "abc@123.com"
[root@manager source]# git config --global user.name "tom"

# 第二步:在版本库中,创建文件并写入内容
[root@manager source]# ls
code.txt  hello  new.c
[root@manager source]# git add *
[root@manager source]# git commit -m "第一个版本:v1.0"

# 查看历史版本记录
[root@manager source]# git log
commit aa8c4ececd1cb4aabc8fcb6e58d3c99e3a133b3e
Author: tom <abc@123.com>
Date:   Tue Sep 8 10:41:09 2020 -0400

    第一个版本:v1.0


# 第三步:修改版本库中的文件的内容
[root@manager source]# echo "aaa">>code.txt 
[root@manager source]# cat code.txt 
test 111
aaa
[root@manager source]# 
[root@manager source]# git add *
[root@manager source]# git commit -m "第二个版本:v2"
[master 14a7831] 第二个版本:v2
 1 file changed, 1 insertion(+)
[root@manager source]# 
[root@manager source]# git log
commit 14a7831e415d0c6a3438d5ef6960da1a00646b8c
Author: tom <abc@123.com>
Date:   Tue Sep 8 10:46:49 2020 -0400

    第二个版本:v2

commit aa8c4ececd1cb4aabc8fcb6e58d3c99e3a133b3e
Author: tom <abc@123.com>
Date:   Tue Sep 8 10:41:09 2020 -0400

    第一个版本:v1.0

# 第四步:再次修改code.txt,再创建一个新版本
[root@manager source]# vim code.txt 
[root@manager source]# 
[root@manager source]# git add *
[root@manager source]# git commit -m "第三个版本:v3"
[master 91d7327] 第三个版本:v3
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@manager source]# 
[root@manager source]# git log
commit 91d7327af1f3714f6052a54e1c2f76267039a38a
Author: tom <abc@123.com>
Date:   Tue Sep 8 10:47:52 2020 -0400

    第三个版本:v3

commit 14a7831e415d0c6a3438d5ef6960da1a00646b8c
Author: tom <abc@123.com>
Date:   Tue Sep 8 10:46:49 2020 -0400

    第二个版本:v2

commit aa8c4ececd1cb4aabc8fcb6e58d3c99e3a133b3e
Author: tom <abc@123.com>
Date:   Tue Sep 8 10:41:09 2020 -0400

    第一个版本:v1.0


# 第五步:恢复到上一个版本
[root@manager source]# cat code.txt 
test 222
aaa
[root@manager source]#  git reset --hard HEAD^
HEAD is now at 14a7831 第二个版本:v2
[root@manager source]# 
[root@manager source]# cat code.txt 
test 111
aaa

# 切换到第一个版本
[root@manager source]# git reset --hard aa8c4e
HEAD is now at aa8c4ec 第一个版本:v1.0
[root@manager source]# cat code.txt 
test 111

# 第六步:查看历史版本的版本号,进行版本切换
[root@manager source]# git reflog
aa8c4ec HEAD@{0}: reset: moving to aa8c4e
14a7831 HEAD@{1}: reset: moving to HEAD^
91d7327 HEAD@{2}: commit: 第三个版本:v3
14a7831 HEAD@{3}: commit: 第二个版本:v2
aa8c4ec HEAD@{4}: commit (initial): 第一个版本:v1.0

[root@manager source]# git reset --hard 91d7327
HEAD is now at 91d7327 第三个版本:v3
[root@manager source]# 
[root@manager source]# cat code.txt 
test 222
aaa

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值