版本控制--git进阶

目录

HEAD指针
Git分支
Git服务器
GitHub

进入正题

HEAD指针

HEAD指针是一个可以在任何分支和版本移动的指针
通过移动指针我们可以将数据还原至任何版本

1.对仓库进行修改 多次提交
[root@xn10 git]# vim init.txt 
[root@xn10 git]# git add .
[root@xn10 git]# git commit -m "第二次提交"
[master a286910] 第二次提交
 1 file changed, 1 insertion(+)
[root@xn10 git]# git config --global pu
pull.octopus   pull.twohead   push.default   
[root@xn10 git]# git config --global push.default simple
[root@xn10 git]# git push 

[root@xn10 git]# git log --oneline 
a286910 第二次提交
bda590b 第一次提交
[root@xn10 git]# git pull
root@201.1.2.100's password: 
Already up-to-date.
[root@xn10 git]# vim init.txt 
[root@xn10 git]# git add .
[root@xn10 git]# git commit -m "第三次提交"
[master 9c3098e] 第三次提交
 1 file changed, 1 insertion(+)
[root@xn10 git]# git config --global push.default simple
[root@xn10 git]# git pull

2.移动指针将数据还原任意版本
[root@xn10 git]# git reflog    //查看有那些版本
9c3098e HEAD@{0}: commit: 第三次提交
a286910 HEAD@{1}: commit: 第二次提交
bda590b HEAD@{2}: commit (initial): 第一次提交
[root@xn10 git]# git reset --hard a286910  还原到第二个版本
HEAD 现在位于 a286910 第二次提交
[root@xn10 git]# cat init.txt 
init date
dierci xiugai

[root@xn10 git]# git reflog     //查看指针移动历史
a286910 HEAD@{0}: reset: moving to a286910

3.误删除后的数据还原操作
[root@xn10 git]# git rm init.txt
rm 'init.txt'
[root@xn10 git]# git commit -m "误删除"
[master d859606] 误删除
 1 file changed, 2 deletions(-)
 delete mode 100644 init.txt
[root@xn10 git]# git reflog 
d859606 HEAD@{0}: commit: 误删除
a286910 HEAD@{1}: reset: moving to a286910
9c3098e HEAD@{2}: commit: 第三次提交
a286910 HEAD@{3}: commit: 第二次提交
bda590b HEAD@{4}: commit (initial): 第一次提交
[root@xn10 git]# git reset  --hard 9c3098e
HEAD 现在位于 9c3098e 第三次提交
[root@xn10 git]# ls
init.txt  xixi

Git分支

1.查看当前分支
[root@xn10 git]# git status 
# 位于分支 master
# 您的分支领先 'origin/master' 共 1 个提交。
#   (使用 "git push" 来发布您的本地提交)
#
无文件要提交,干净的工作区
[root@xn10 git]# git branch -v
* master 9c3098e [领先 1] 第三次提交
[root@xn10 git]# 

2.创建分支
[root@xn10 git]# git branch hotfix
[root@xn10 git]# git branch feature
[root@xn10 git]# git branch -v
  feature 9c3098e 第三次提交
  hotfix  9c3098e 第三次提交
* master  9c3098e [领先 1] 第三次提交
[root@xn10 git]# 
3.切换分支
[root@xn10 git]# git checkout hotfix 
<--- 拼写建议 --->
[root@xn10 git]# git checkout hotfix 
hotfix
hot fix	hot-fix	hotfoot
4.合并分支

合并分支必须切换到要合并的主分支里
并且要合并的主分支里没有要合并的分支中的数据

[root@xn10 git]# git merge feature 
Merge made by the 'recursive' strategy.
[root@xn10 git]# git branch -v
  feature bf84597 nnn
  hotfix  9c3098e 第三次提交
* master  d257a12 [领先 6] Merge branch 'feature' s

5.解决版本分支的冲突问题
1)在不同分支中修改相同文件的相同行数据,模拟数据冲突。

[root@web2 project]# git checkout hotfix
[root@web2 project]# echo "AAA" > a.txt
[root@web2 project]# git add .
[root@web2 project]# git commit -m "add a.txt by hotfix"

[root@web2 project]# git checkout master
[root@web2 project]# echo "BBB" > a.txt
[root@web2 project]# git add .
[root@web2 project]# git commit -m "add a.txt by master"
[root@web2 project]# git merge hotfix
自动合并 a.txt
冲突(添加/添加):合并冲突于 a.txt
自动合并失败,修正冲突然后提交修正的结果。

2)查看有冲突的文件内容,修改文件为最终版本的数据,解决冲突。

[root@web2 project]# cat a.txt				#该文件中包含有冲突的内容
<<<<<<< HEAD
BBB
=======
AAA
>>>>>>> hotfix
[root@web2 project]# vim a.txt              #修改该文件,为最终需要的数据,解决冲突
BBB

[root@web2 project]# git add .
[root@web2 project]# git commit -m "resolved"

Git服务器

SSH协议服务器
1.创建基于密码验证的ssh协议服务器
[root@xn9 lnmp_soft]# git init --bare /var/123/base_ssh
初始化空的 Git 版本库于 /var/123/base_ssh/
2.客户端生成 SSH秘钥,实现免密码登录git服务器
[root@xn10 ~]# ssh-keygen -f /root/.ssh/id_rsa -N ''    
[root@xn10 ~]# ssh-copy-id 201.1.2.100
[root@xn10 ~]# git clone root@201.1.2.100:/var/123/base_ssh
正克隆到 'base_ssh'...
warning: 您似乎克隆了一个空版本库。
Git协议服务器
1.安装git-daemon软件包
[root@xn9 lnmp_soft]# yum -y install git-daemon
2.创建版本仓库
[root@xn9 lnmp_soft]# git init --bare /var/123/base_git
初始化空的 Git 版本库于 /var/123/base_git/
3.修改配置文件 重启服务
[root@xn9 lnmp_soft]# vim /usr/lib/systemd/system/git@.service 
[root@xn9 lnmp_soft]# systemctl start git.socket

修改前内容如下:
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/lib/git
–export-all --user-path=public_git --syslog --inetd –verbose
修改后内容如下:少了/lib
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/git
–export-all --user-path=public_git --syslog --inetd –verbose

HTTP协议服务器
1.安装gitweb,httpd软件包
在[root@xn9 lnmp_soft]# yum -y install httpd gitweb
2.修改gitweb,设置仓库根目录
[root@xn9 lnmp_soft]# vim +11 /etc/gitweb.conf 
3.创建版本仓库
[root@xn9 lnmp_soft]# git  init --bare  /var/123/base_http
初始化空的 Git 版本库于 /var/123/base_http/
4.启服务

确认80端口没有被别的服务占用 否则httpd服务起不来

[root@xn9 lnmp_soft]# /usr/local/nginx/sbin/nginx -s stop  //关闭nginx服务
[root@xn9 lnmp_soft]# systemctl restart httpd    //启动httpd服务

客户端访问git的方式

本地访问
git clone file:///var/git

通过远程访问
git clone root@192.168.2.100:/var/git

通过web访问
服务端需要搭建web服务器
git clone http://192.168.2.100/git/

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值