GitLab

gitlab 版本控制

1. 版本控制介绍

版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。

主要功能

  • 历史记录

版本控制记录了仓库中每个文件的所有变更历史。开发者可以查看每个提交的详细信息,包括作者、提交时间、提交消息等。每一次文件的改变,文件的版本号都将增加。

  • 分支管理

版本控制允许开发者创建多个并行的分支,用于不同的功能开发、修复错误等。开发者可以切换、创建、合并和删除分支,以有效管理代码的不同版本。

  • 合并冲突解决

软件开发往往是多人协同作业,当多个开发者同时修改同一文件时,可能会发生合并衝突。版本控制提供了合并冲突解决的工具和界面,使开发者能够手动解决冲突并合并代码,提高协同开发的效率。并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。

  • 回滚更改

如果出现了错误或不需要的更改,开发者可以使用版本控制的回滚功能将代码恢复到之前的状态。

  • 标签和里程碑

开发者可以使用标签和里程碑来标记特定的版本或重要的里程碑。这有助于团队在开发过程中进行版本控制和PO管理。


具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,开发出所需的目标版本。当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。

例如当开发需求或需求变更被取消时,就需要有能力将版本回退到开发基线版本。在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,将对应不同需求的不同分支重新组合归并,形成新的升级包版本。

版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性。版本在生成过程中,自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,如需要对它们进行变更,则应按照变更控制的流程来进行操作。

常用的版本控制工具

  • gitlab
  • subversion

SVN 教程

2. gitlab部署

主机名ip系统版本
kiwi222192.168.234.33CentOS-8
2.1 安装git以及依赖包
## 关闭防火墙以及selinux
[root@kiwi222 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@kiwi222 ~]# setenforce 0
[root@kiwi222 ~]# 

[root@kiwi222 ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config 

[root@kiwi222 ~]# yum install -y git perl curl openssh-server openssh-clients postfix cronie
[root@kiwi222 ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-python-2.5-34.el7.x86_64.rpm

[root@kiwi222 ~]# ls
anaconda-ks.cfg  policycoreutils-python-2.5-34.el7.x86_64.rpm

[root@kiwi222 ~]# rpm -ivh --nodeps --force policycoreutils-python-2.5-34.el7.x86_64.rpm
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:policycoreutils-python-2.5-34.el7################################# [100%]
[root@kiwi222 ~]# 
2.2 下载gitlab的rpm包
[root@kiwi222 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
[root@kiwi222 ~]# ls
anaconda-ks.cfg                       policycoreutils-python-2.5-34.el7.x86_64.rpm
gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
2.3 安装gitlab的rpm包
[root@kiwi222 ~]# rpm -ivh gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-16.4.1-ce.0.el7        ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=16-4

## 出现一个狐狸头表示已经安装成功
2.4 配置gitlab的配置文件
[root@kiwi222 ~]# vim /etc/gitlab/gitlab.rb 
···················略
##! address from AWS. For more details, see:
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'http://192.168.234.33'   ### //修改这一行

·································略

gitlab_workhorse['auth_backend'] = "http://localhost:8080"  ###  //去掉这一行的注释
## Roles for multi-instance GitLab

···················略
2.5 重新加载配置文件并重启gitlab
## 开启邮箱服务
[root@kiwi222 ~]# systemctl enable --now postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@kiwi222 ~]# 


## 加载配置文件之前
[root@kiwi222 ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port       Peer Address:Port    Process    
LISTEN    0         128                0.0.0.0:22              0.0.0.0:*                  
LISTEN    0         100              127.0.0.1:25              0.0.0.0:*                  
LISTEN    0         128                   [::]:22                 [::]:*                  
LISTEN    0         100                  [::1]:25                 [::]:* 

## 重新加载配置文件
[root@kiwi222 ~]# gitlab-ctl reconfigure

··················略

NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

gitlab Reconfigured!


## 重新加载配置文件之后
[root@kiwi222 ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port       Peer Address:Port    Process    
LISTEN    0         1024             127.0.0.1:9093            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:9100            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:9229            0.0.0.0:*                  
LISTEN    0         128              127.0.0.1:9168            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:8080            0.0.0.0:*                  
LISTEN    0         511                0.0.0.0:80              0.0.0.0:*                  
LISTEN    0         128              127.0.0.1:8082            0.0.0.0:*                  
LISTEN    0         2048             127.0.0.1:9236            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:8150            0.0.0.0:*                  
LISTEN    0         128                0.0.0.0:22              0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:8151            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:8153            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:8154            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:8155            0.0.0.0:*                  
LISTEN    0         128              127.0.0.1:8092            0.0.0.0:*                  
LISTEN    0         511                0.0.0.0:8060            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:9121            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:9090            0.0.0.0:*                  
LISTEN    0         1024             127.0.0.1:9187            0.0.0.0:*                  
LISTEN    0         1024                     *:9094                  *:*                  
LISTEN    0         128                  [::1]:9168               [::]:*                  
LISTEN    0         128                   [::]:22                 [::]:*  


### 重新加载gitlab
[root@kiwi222 ~]# gitlab-ctl restart
2.6 查看gitlab版本
[root@kiwi222 ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 16.4.1
[root@kiwi222 ~]# 

image-20231007153753729

能进来这页面就代表已经下载成功

2.7 在web端修改密码
## 这个是gitlab的初始密码文件,在24小时之后会自动删除
[root@kiwi222 ~]# cat /etc/gitlab/initial_root_password 
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: qLbIJDp0SgCFfttEatvEHvs4dH6ZKXJrPQDDZoN3kX4=    ### //这行为初始密码

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
[root@kiwi222 ~]# 

image-20231007154103262

点击搜索

image-20231007154140761

image-20231007154205000

image-20231007154241692

这里就可以更改密码

image-20231007154259238

2.8 破解密码
[root@kiwi222 ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------
 Ruby:         ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
 GitLab:       16.4.1 (e6801ed8d44) FOSS
 GitLab Shell: 14.28.0
 PostgreSQL:   13.11
------------------------------------------------------------[ booted in 28.67s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0> user = User.where(id: 1).first     ## //id为1的是超级管理员
=> #<User id:1 @root>
irb(main):005:0> user.password = 'kiwi222...'       ## //密码必须至少8个字符
=> "kiwi222..."
irb(main):006:0> user.password_confirmation = 'kiwi222...'
=> "kiwi222..."
irb(main):007:0> user.save
=> true
irb(main):008:0> exit
[root@kiwi222 ~]# 

验证登录

image-20231007155148751

密码破解成功

image-20231007155205704

3. 创建项目

3.1 创建一个新项目

image-20231007155354847

image-20231007155416141

image-20231007155727724

点击创建

image-20231007160017944

创建成功

image-20231007160046960

3.2 上传一个文件
[root@kiwi222 kiwi]# git config --global user.name "root"   ## 指定用户
[root@kiwi222 kiwi]# git config --global user.email "123@abc.com"  ## 指定邮箱


[root@kiwi222 ~]# git clone http://192.168.234.33/root/kiwi.git
Cloning into 'kiwi'...
Username for 'http://192.168.234.33': root     ##用户名
Password for 'http://root@192.168.234.33':     ##密码
warning: You appear to have cloned an empty repository.
[root@kiwi222 ~]# 

## 可以看到已经有一个新目录
[root@kiwi222 ~]# ls
anaconda-ks.cfg                       kiwi
gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm  policycoreutils-python-2.5-34.el7.x86_64.rpm
[root@kiwi222 ~]# 


[root@kiwi222 ~]# cd kiwi/
[root@kiwi222 kiwi]# git switch --create main  ##创建一个主分支
Switched to a new branch 'main'
[root@kiwi222 kiwi]# echo 'kiwi123' > txt1
[root@kiwi222 kiwi]# ls
txt1
[root@kiwi222 kiwi]# git add txt1   ##添加文件
[root@kiwi222 kiwi]# git commit -m "first commit"  ##提交
[main (root-commit) 27bc5ac] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 txt1
 
[root@kiwi222 kiwi]# git push --set-upstream origin main   ## 上传
Username for 'http://192.168.234.33': root
Password for 'http://root@192.168.234.33': 
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 201 bytes | 201.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.234.33/root/kiwi.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
[root@kiwi222 kiwi]# 

重新加载进来

image-20231007161336904

可以看见已经上传成功

image-20231007161404870

点进去看看内容

image-20231007161427416

image-20231007161433266

除此之外还可以在web上添加

image-20231007161532339

4. 管理用户与组

4.1 创建一个新组

image-20231007161818945

image-20231007161900266

image-20231007162002457

image-20231007162054918

点击添加

image-20231007162107331

创建成功

image-20231007162122417

4.2 创建一个新用户

image-20231007162204957

创建用户

image-20231007162307485

创建完成之后点编辑
image-20231007162334867
修改密码

image-20231007162413918

4.3 将用户添加到组

image-20231007163126013

image-20231007163259918

邀请

image-20231007163311518

image-20231007163457192

image-20231007163542215

添加成功

image-20231007163555778

4.4 允许组或者用户访问项目

image-20231007163758863

image-20231007163818569

这里点邀请一个组

image-20231007163856460

image-20231007163947094

image-20231007164004421

切换用户

先退出登录

image-20231007164050417

登录

image-20231007164136437

点击进去

image-20231007164319791

可以看见已经有文件

image-20231007164355255

可以编辑

image-20231007164552439

部署完成

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值