CI Continuous Integration - git and gitlab

Overview git version control system

Git basic overview

Git is a free open source distributed version control system designed to quickly and efficiently handle everything from small to large projects.

Git installation configuration

#安装Git
yum install -y git

#配置用户信息,用户名称和电子邮件地址,每次 Git提交时都会引用这两条信息,说明是谁提交了更新;   
git config --global user.name "onelpc"  
git config --global user.email "[email protected]"
git config --global color.ui true  #配置颜色,非必须

#会生成一个配置文件
[root@gitlab ~]# cat ~/.gitconfig 
[user]
    name = onelpc
    email = [email protected]
[color]
    ui = true

Git basic commands

   add       #添加文件内容至索引
   bisect    #通过二分查找定位引入 bug 的变更
   branch    #列出、创建或删除分支
   checkout  #检出一个分支或路径到工作区
   clone     #克隆一个版本库到一个新目录
   commit    #记录变更到版本库
   diff      #显示提交之间、提交和工作区之间等的差异
   fetch     #从另外一个版本库下载对象和引用
   grep      #输出和模式匹配的行
   init      #创建一个空的 Git 版本库或重新初始化一个已存在的版本库
   log       #显示提交日志
   merge     #合并两个或更多开发历史
   mv        #移动或重命名一个文件、目录或符号链接
   pull      #获取并合并另外的版本库或一个本地分支
   push      #更新远程引用和相关的对象
   rebase    #本地提交转移至更新后的上游分支中
   reset     #重置当前HEAD到指定状态
   rm        #从工作区和索引中删除文件
   show      #显示各种类型的对象
   status    #显示工作区状态
   tag       #创建、列出、删除或校验一个GPG签名的 tag 对象

Git basic operations

Create a local git repository

#创建本地工作目录
mkdir /demo
cd /demo/

#初始化为git工作目录
git init 

submit data

#提交文件到缓存区,
git add file1
git add .   //点(.)代表当前目录下所有文件

#提交文件到本地仓库
git commit -m "添加file1"

#当我们修改了很多文件,而不想每一个都add,想commit自动来提交本地修改(-a参数不会造成新文件被提交,只能修改)
git commit -a -m "修改了xxx等x个文件"

Mobile Data

git mv file1 file4  #修改文件名称
git commit -m 'change file name' #提交

Comparative data

#本地文件与缓冲区文件对比
git diff file1
 
#缓冲区文件与仓库文件对比
git diff --cached file1

Revocation modified files

#提交到缓冲的区文件撤回
git reset HEAD filename

#未add到缓冲区的文件撤回
git checkout filename

View version rollback

#查看现在版本
git log --oneline
git reset --hard 942bdf3

#查看所有历史版本
git reflog --oneline
git reset --hard 942bdf3

Git Branch Management

#增加一个新分支
git branch dev01

#切换分支
git checkout  dev01

#查看当前分支情况/所在分支(*代表当前所在)
git branch

#切回主分支
git checkout  master

#在主分支合并dev01分支
git merge dev01  -m '注释'

#删除dev01分支
git branch -d dev01

Git Label Management

#给当前版本打标签
git tag v1.2 

#删除标签
git  tag  -d  v1.2

#给任意版本打标签
git tag  -a v1.0  -m  '优化了1111  修复bug'  a119962 

#查看代码标签信息,(-n,显示tag信息)
git tag -n    

Git remote repository

The remote repository is associated with a local warehouse

gitee create a warehouse

Generate a public key file

[root@gitlab ~/demo]# ssh-keygen 
[root@gitlab ~/demo]# cat /root/.ssh/id_rsa.pub 
>>将公钥内容复制

Add the public key to gitee

Follow the prompts

Submit a file to a remote repository

工作区:   touch file5
暂存区:   git add .
本地仓库:  git commit -m "new file file5"
远程仓库:  git push origin master     

Gitlab warehouse

Gitlab Introduction

gitlab warehouse is an open source community edition ce, Enterprise Edition ee. (git basis based development)

gitlab deployment

#下载gitlab
[root@gitlab ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.0-ce.0.el7.x86_64.rpm

#安装gitlab 依赖
[root@gitlab ~]# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
#安装gitlab
[root@gitlab ~]# yum localinstall -y gitlab-ce-12.3.0-ce.0.el7.x86_64.rpm
    
#配置gitlab
1.备份gitlab配置文件
[root@gitlab ~]# cp -v /etc/gitlab/{gitlab.rb,gitlab.rb_bak}
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
2.修改gitlab访问的url 
external_url 'http://gitlab.oldxu.com'
3.关闭一些没有用程序
prometheus['enable'] = false
prometheus_monitoring['enable'] = false
4.配置邮箱
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = "[email protected]"  # 发件邮箱
gitlab_rails['gitlab_email_display_name'] = 'OneLpc' # 发件人显示名称
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]" #发件人邮箱账户
gitlab_rails['smtp_password'] = "qweasdzxc"  #发件人邮箱客户端授权码
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

#初始化gitlab
[root@gitlab ~]# gitlab-ctl reconfigure

#启动 gitlab
[root@gitlab ~]# gitlab-ctl start

浏览器访问,设置密码

Speaking Gitlab

Download the finished package: https: //gitlab.com/xhang/gitlab

#停止gitlab
[root@gitlab ~]# gitlab-ctl stop

#备份原文件
[root@gitlab ~]# \cp -rp /opt/gitlab/embedded/service/gitlab-rails{,.bak_$(date +%F)}

#替换语言包
[root@gitlab ~]# tar xf gitlab-12-0-stable-zh.tar.gz
[root@gitlab ~]# \cp -r gitlab-12-0-stable-zh/* /opt/gitlab/embedded/service/gitlab-rails/

#重新加载gitlab
[root@gitlab ~]# gitlab-ctl reconfigure

#启动gitlab
[root@gitlab ~]# gitlab-ctl start

#访问gitlab网站设置语句
选择右上角--->setttings---》Preferences -->Language

Gitlab backup

#手动备份
[root@gitlab-ce ~]# gitlab-rake gitlab:backup:create
>>默认的备份目录:`/var/opt/gitlab/backups`目录下tar的压缩包


#修改gitlab备份目录
[root@gitlab-ce ~]# vim /etc/gitlab/gitlab.rb
...
gitlab_rails['backup_path'] = "/data/gitlab/backups"        #控制备份后的产物放在哪里   
gitlab_rails['backup_keep_time'] = 604800                   #保留多久的数据
...
[root@gitlab-ce ~]# gitlab-ctl reconfigure

Gitlab Data Recovery

# 停止相关数据连接服务
[root@gitlab-ce ~]# gitlab-ctl stop unicorn
[root@gitlab-ce ~]# gitlab-ctl stop sidekiq

# 从1576659867_2019_12_18_12.3.5编号备份中恢复
[root@gitlab-ce ~]# gitlab-rake gitlab:backup:restore BACKUP=1576659867_2019_12_18_12.3.5

# 启动Gitlab
[root@gitlab-ce ~]# gitlab-ctl start

Gitlab migration

Migration as backup and recovery steps, like the old server only need to copy the backup file to the new server

Note that on the new server Gitlabversion must create a backup when Gitlabthe same version number.

Gitlab upgrade

Close gitlab Service

[root@gitlab-ce ~]# gitlab-ctl stop unicorn
[root@gitlab-ce ~]# gitlab-ctl stop sidekiq
[root@gitlab-ce ~]# gitlab-ctl stop nginx

Data backup gitlab

[root@gitlab-ce ~]# gitlab-rake gitlab:backup:create

Install the new version of the rpm package

//直接安装
[root@gitlab-ce ~]# yum install gitlab-ce-12.3.0-ce.0.el7.x86_64.rpm

//报错.
Error executing action `run` on resource 'ruby_block[directory resource: /var/opt/gitlab/git-data/repositories]'

//解决方法:
[root@gitlab-ce ~]# chmod 2770 /var/opt/gitlab/git-data/repositories

Start gitlab

[root@gitlab-ce ~]# gitlab-ctl reconfigure
[root@gitlab-ce ~]# gitlab-ctl restart
[root@gitlab-ce ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 12.3.0

Gitlab change the default Nginx

slightly

Guess you like

Origin www.cnblogs.com/lpcsf/p/12061106.html