linux怎么查看本机内存大小
227
2022-11-09
持续集成之Gitlab安装与应用
Gitlab 是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的 Git 项目仓库,可通过Web 界面进行访问公开的或者私人的项目 Gitlab 拥有与 Github 类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,他非常易于浏览提交过的版本并提供一个文件历史库。他还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找
一、环境准备
如果是测试环境,其内存建议2G及以上,可以去清华开源镜像站下载所需gitlab版本,其安装后,会自动安装nginx提供web界面,所以要避免80端口占用。
二、安装部署gitlab
1. 安装gitlab
[root@git /]# mkdir git [root@git /]# cd git/ [root@git git]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.9.8-ce.0.el7.x86_64.rpm [root@git git]# rpm -ivh gitlab-ce-11.9.8-ce.0.el7.x86_64.rpm #当gitlab安装完毕后会有一个大狐狸头 #由于我不打算做域名解析,所以需要修改其配置文件 [root@git git]# vim /etc/gitlab/gitlab.rb external_url ' # 将原本的域名改为本机IP [root@git /]# gitlab-ctl reconfigure #重新配置gitlab,就算不修改配置文件,也需要在安装后重新配置gitlab,此处会等一会 [root@git /]# netstat -anput | grep -w 80 #确定nginx在监听80端口
[root@git /]# ssh-keygen -t rsa -C "848369866@qq.com" [root@git /]# cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7mTAcNqGbsRoPPAd2M+xfdVfsa4lLPVs37WHbM+iept0DdSIgVaoz++w4oHTccWcH6K5hvCJo5AvTzIuSn3rAV8E6sROL2yCafcLE+//rSpW5/cenvsuYhNV5jkqfuCs1moVev0BHnW//9XZJpyQFIQ8JNlASFGmRXOycNuP9NeacSo5IoXjRzHTA28674+LZwo6D6+klfAYo75rD7JQ61DhrAEq/xBHQ+5zigo6i95xsRdUMPpKRsb0fruTBYUC0jwNfKzgal1CuGTmqJ+l9MI4cnbHNYk2TYP74NgcUYHfp0n6Lr7HkUDAtsyGbT9zPfatU3nVOihN8efdupb8d 848369866@qq.com
[root@git /]# git clone git@192.168.171.134:root/test1.git # 进行克隆 [root@git /]# cd test1/ # 可以看到这里和刚才库里的东西一样 [root@git test1]# ls README.md #定义用户名及email [root@git test1]# git config --global user.name "test" [root@git test1]# git config --global user.email "test@test.com" #创建测试文件,并推送到远端库中测试 [root@git test1]# echo "aaaa" > test.txt [root@git test1]# git add test.txt [root@git test1]# git commit -m "alter from 192.168.171.134" [master 81dc1f8] alter from 192.168.171.134 1 file changed, 1 insertion(+) create mode 100644 test.txt [root@git test1]# git push origin master
三、远端库的基本操作
当你从远端仓库克隆时,实际上git自动把本地的master分支和远端的master分支对应起来了,并且远程仓库的默认名称是origin。要查看远程库的信息,使用以下命令:
[root@git test1]# git remote # 简略信息 origin [root@git test1]# git remote -v # 详细信息 origin git@192.168.171.134:root/test1.git (fetch) origin git@192.168.171.134:root/test1.git (push)
推送分支:
[root@git test1]# git push origin master #推送本地的master分支 [root@git test1]# git push origin dev #推送本地的dev分支,若远端没有dev分支,会自动创建
抓取分支:
[root@git test1]# git pull origin dev #根据提示将远端的dev分支抓取下来
当我们从远程库克隆时,默认情况下,只能看到master分支,可以使用git branch命令确认。解决多人协作容易产生的问题当我们整个小组对同一个分支进行开发时,如果在你提交之前,你的同事已经修改了分支的内容并推送到远端仓库,而碰巧你也对同样的文件做了修改,并试图推送,那么会推送失败,因为你的同事的最新提交的数据和你试图提交的数据有冲突(你本地的内容比远端仓库的旧了),解决的办法会在提示你推送失败的返回信息中给出,这里我们模拟一下这一过程。
[root@git /]# mkdir test2 [root@git /]# cd test2/ [root@git test2]# git clone git@192.168.171.134:root/test1.git [root@git test2]# cd test1/ [root@git test1]# git checkout -b dev Switched to a new branch 'dev' [root@git test1]# echo "bbbb" > tmp.txt [root@git test1]# git add tmp.txt [root@git test1]# git commit -m "commit from /test2" [dev ba44ec3] commit from /test2 1 file changed, 1 insertion(+) create mode 100644 tmp.txt [root@git test1]# git push origin dev
[root@git /]# cd root/test1/ #进入root目录下的远程仓库并创建dev分支,推送内容至远端仓库 [root@git test1]# git checkout -b dev Switched to a new branch 'dev' [root@git test1]# echo "ccccc" > root.txt [root@git test1]# git add root.txt [root@git test1]# git commit -m "commit from /root" [dev f8fd78d] commit from /root 1 file changed, 1 insertion(+) create mode 100644 root.txt [root@git test1]# git push origin dev #此时我们推送,就会提示以下错误 To git@192.168.171.134:root/test1.git ! [rejected] dev -> dev (fetch first) error: failed to push some refs to 'git@192.168.171.134:root/test1.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. #无法推送一些引用到'git@192.168.171.134:root/test1.git' #提示远程版本库有我们本地版本库没有的提交,所以需要先将远端版本库pull下来,再提交 [root@git test1]# git pull origin dev #根据提示将远端的dev分支pull下来 [root@git test1]# ls README.md root.txt test.txt tmp.txt [root@git test1]# git push origin dev #然后再次将本地的dev分支推送到gitlab,即可成功
[root@git test1]# git checkout master # 切换到master分支 Switched to branch 'master' [root@git test1]# git merge dev # 合并dev分支 Updating 81dc1f8..386d906 Fast-forward root.txt | 1 + tmp.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 root.txt create mode 100644 tmp.txt [root@git test1]# git pull Already up-to-date. [root@git test1]# git add * [root@git test1]# git commit -m "提交" [root@git test1]# git push origin master # 推送到远端库
[root@git test1]# git branch -d dev # 删除本地的dev分支 Deleted branch dev (was 386d906). [root@git test1]# git branch -r -d origin/dev # #删除指定的远程分支 Deleted remote branch origin/dev (was 386d906). [root@git test1]# git push origin :dev # #将删除的分支提交到远程版本库中 To git@192.168.171.134:root/test1.git - [deleted] dev
四、重置gitlab管理员密码
[root@git /]# gitlab-rails console production #执行该命令,只有第一个命令字可以tab出来
-------------------------------------------------------------------------------------
GitLab: 11.9.8 (48528bc)
GitLab Shell: 8.7.1
postgresql: 9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.1)
irb(main):001:0> user = User.where(id:1).first
=> #
至此,再次登录,就需要使用新密码test1234进行登录了。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~