GIT

# git

## 1 运维发展过程

![image-20250327111155200](C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20250327111155200.png)

“`sh
https://www.processon.com/diagraming/67e4b7550804c26b55b70c19
“`

## 2 软件生命周期

“`sh
1 立项
目标与方向、调查
2 开发
需求分析、选择技术栈、代码仓库(git、github、gitee(码云)、gitlab、svn)、功能合并
3 运维
测试QA、打包工具maven、部署、性能测试,自动化测试工具
4 消亡

“`

## 3 ci/cd

“`sh
ci continuous integreation 持续集成: 开发的代码集成到代码仓库
cd continuous delivery 持续交付: 从代码仓库拉取代码部署到测试环境
cd continuous deployment 持续部署: 从代码仓库拉取代码部署到生产环境
“`

## 4 DevOps

“`sh
1 DevOps
Development 开发
Operations 运维

2 DevSecOps
Dev开发
Sec Secure 安全
Ops运维
“`

![image-20250327112340244](C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20250327112340244.png)

## 5 虚拟机准备

| 角色 | 主机名 | ip | 配置 |
| —————– | ————– | ————————– | —- |
| gitlab代码仓库 | devops-gitlab | 192.168.137.71/172.16.1.71 | 2c4g |
| jenkins | devops-jenkins | 192.168.137.72/172.16.1.72 | 2c4g |
| sonarqube代码检查 | devops-sonar | 192.168.137.73/172.16.1.73 | 1c1g |
| nexus | devops-nexus | 192.168.137.74/172.16.1.74 | 1c1g |

## 6 git和svn

| | git | svn |
| ——– | ———————————————- | ————————————– |
| 共同点 | 存放代码,版本控制 | 存放代码,版本控制 |
| 工作模式 | 分布式(git代码仓库挂了,本地的代码仍旧可以使用) | 中心化(权限集中) |
| 使用 | 入门较难,熟练后容易使用,目前使用率高 | 入门比较简单,服务端linux,客户端windows |
| 分支 | 创建和维护分支方便 | 创建和维护分支繁琐 |

## 7 部署git

“`sh
[root@devops-gitlab ~]# yum -y install git
“`

## 8 git极速上手

“`sh
1 创建项目目录(代码目录)
[root@devops-gitlab ~]# mkdir -p /app/src/bugc-live
[root@devops-gitlab ~]# cd /app/src/bugc-live/
[root@devops-gitlab /app/src/bugc-live]# ll
total 0

2 对代码目录进行初始化(书写代码的时候)成为git仓库
2.1 配置用户
[root@devops-gitlab /app/src/bugc-live]# git config –global user.name ‘zhangsan’

[root@devops-gitlab /app/src/bugc-live]# git config –global user.email ‘644574771@qq.com’

[root@devops-gitlab /app/src/bugc-live]# git config –global -l
user.name=zhangsan
user.gender=nan

2.2 初始化代码目录
[root@devops-gitlab /app/src/bugc-live]# git init
Initialized empty Git repository in /app/src/bugc-live/.git/

[root@devops-gitlab /app/src/bugc-live]# ll .git/
total 12
drwxr-xr-x 2 root root 6 Mar 27 12:57 branches
-rw-r–r– 1 root root 92 Mar 27 12:57 config
-rw-r–r– 1 root root 73 Mar 27 12:57 description
-rw-r–r– 1 root root 23 Mar 27 12:57 HEAD
drwxr-xr-x 2 root root 332 Mar 27 12:57 hooks
drwxr-xr-x 2 root root 21 Mar 27 12:57 info
drwxr-xr-x 4 root root 30 Mar 27 12:57 objects
drwxr-xr-x 4 root root 31 Mar 27 12:57 refs

3 书写代码,添加文件
[root@devops-gitlab /app/src/bugc-live]# echo git_test > index.html

3.1 查看仓库状态
root@devops-gitlab /app/src/bugc-live]# git status
On branch master

No commits yet

Untracked files:
(use “git add …” to include in what will be committed)
index.html

nothing added to commit but untracked files present (use “git add” to track)
[root@devops-gitlab /app/src/bugc-live]#

3.2 进行提交
[root@devops-gitlab /app/src/bugc-live]# git add .
[root@devops-gitlab /app/src/bugc-live]# git status
On branch master

No commits yet

Changes to be committed:
(use “git rm –cached …” to unstage)
new file: index.html

3.3 提交到本地仓库
[root@devops-gitlab /app/src/bugc-live]# git commit -m ‘项目开始,完成度60%’
[master (root-commit) f248882] 项目开始,完成度60%
1 file changed, 1 insertion(+)
create mode 100644 index.html
“`

9 git修改与回滚

“`sh
1 修改文件内容
vi或echo修改

再次提交
git add .
git commit -m ‘项目完成90%’

2进行回滚
[root@devops-gitlab /app/src/bugc-live]# echo “test_git_reflog” > test_git_reflog.html
[root@devops-gitlab /app/src/bugc-live]# git add .
[root@devops-gitlab /app/src/bugc-live]# git commit -m ‘项目完成90%’
[master 0e79f06] 项目完成90%
1 file changed, 1 insertion(+)
create mode 100644 test_git_reflog.html
[root@devops-gitlab /app/src/bugc-live]# git reflog
0e79f06 (HEAD -> master) HEAD@{0}: commit: 项目完成90%
f248882 HEAD@{1}: commit (initial): 项目开始,完成度60%

[root@devops-gitlab /app/src/bugc-live]# git reset –hard f248882
HEAD is now at f248882 项目开始,完成度60%
[root@devops-gitlab /app/src/bugc-live]# ll
total 4
-rw-r–r– 1 root root 9 Mar 27 12:58 index.html
[root@devops-gitlab /app/src/bugc-live]#

此时新建的test_git_reflog已经不见了

“`

## 9 git命令与含义

| 命令 | 含义 |
| —————————- | ———————————————————— |
| git init | 初始化本地仓库目录,每个独立的代码目录(新的)就要运行下..git目录 |
| git config –global | 邮箱,用户名,颜色,全局系统中设置1次即可 |
| git add | 提交数据到缓冲区,git add .(所有文件)或git add 文件 |
| git commit | 把暂存区的数据提交到本地仓库-m “标记/说明” |
| git status | 显示工作空间的状态 |
| git log | 查看提交记录 |
| git reflog | 查看提交记录 |
| git reset | 回滚 |
| git reset –soft cid(版本号) | 把指定的版本数据内容下载到暂存区 |
| git reset HEAD | 暂存区–>工作空间(被修改的状态) |
| git checkout | 文件下载到工作空间并可以使用 git checkout . 或git checkout 文件 |
| git reset –mix 版本号 | |
| git reset –hard 版本号 | 把本地仓库指定版本信息数据下载到工作目录中 |

## 10 git区域与状态

![image-20250327152053900](C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20250327152053900.png)

## 11 git分支branch

“`sh
分支即是平行空间,假设你在为某个手机系统研发拍照功能,代码已经完成了80%,但如果将这不完整的代码直接提交到git仓库中,又有可能影响到其他人的工作,此时我们便可以在该软件的项目之上创建一个名叫”拍照功能”的分支,

这种分支只会属于你自己,而其他人看不到,等代码编写完成后再与原来的项目主分支合并下即可,这样即能保证代码不丢失,又不影响其他人的工作。
默认的分支-master 主分支,这个分支的代码一般都是可用,可以部署到生产环境的。

一般开发人员开发代码的时候创建dev分支,shopping分支。
其他分支中的代码开发与测试完成要与主分支代码进行合并.
应用名称分支每个分支对应独立功能。
“`

![image-20250327152542232](C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20250327152542232.png)

“`sh
案例
默认主分支,完成直播功能,并提交

[root@devops-gitlab /app/src/bugc-live]# echo “complete” >> index.html
[root@devops-gitlab /app/src/bugc-live]# git add .
[root@devops-gitlab /app/src/bugc-live]# git commit -m “complete 100%”
[master eb2b1b0] complete 100%
1 file changed, 1 insertion(+)

2 创建shopping分支,书写代码
[root@devops-gitlab /app/src/bugc-live]# git branch
* master
[root@devops-gitlab /app/src/bugc-live]# #创建分支
[root@devops-gitlab /app/src/bugc-live]# git branch shopping
[root@devops-gitlab /app/src/bugc-live]# git branch
* master
shopping

3 切换分支
[root@devops-gitlab /app/src/bugc-live]# git checkout shopping
Switched to branch ‘shopping’
[root@devops-gitlab /app/src/bugc-live]#

4 查看切换结果
[root@devops-gitlab /app/src/bugc-live]# git branch
master
* shopping

5 书写shopping代码,并提交
[root@devops-gitlab /app/src/bugc-live]# echo ‘shopping 90%’ > shopping.html
[root@devops-gitlab /app/src/bugc-live]# git add .
[root@devops-gitlab /app/src/bugc-live]# git commit -m ‘shopping 90%’
[shopping 3744f29] shopping 90%
1 file changed, 1 insertion(+)
create mode 100644 shopping.html

root@devops-gitlab /app/src/bugc-live]# echo ‘shopping 100%’ > shopping.html
[root@devops-gitlab /app/src/bugc-live]# git add .
[root@devops-gitlab /app/src/bugc-live]# git commit -m ‘shopping 100%’
[shopping ac51a20] shopping 100%
1 file changed, 1 insertion(+), 1 deletion(-)
[root@devops-gitlab /app/src/bugc-live]#

6 将shopping合并到master分支中
[root@devops-gitlab /app/src/bugc-live]# #将shopping合并到master分支中
[root@devops-gitlab /app/src/bugc-live]# git checkout master
Switched to branch ‘master’
[root@devops-gitlab /app/src/bugc-live]# git merge shopping
Updating eb2b1b0..ac51a20
Fast-forward
shopping.html | 1 +
1 file changed, 1 insertion(+)
create mode 100644 shopping.html
“`

## 12 git 分支命令总结

| git分支相关命令 | 说明 |
| ——————– | ———————— |
| git branch | 查看分支 |
| git branch name | 创建分支 |
| git branch -d name | 删除分支 |
| git checkout name | 切换分支 |
| git merge name | 合并分支 |
| git checkout -b name | 创建分支并切换到这个分支 |

## 13 tag标签

“`sh
1 创建标签
COMMITID的一个别名,COMMITID不好记忆,标签相对的好记忆。
git tag -a “标签名” -m “描述”

基于当
前最新的COMMITID
git tag -a “标签名称” -m “描述” commitID 指定版
本打标签
#如何上传标签
git push origin –tags
git push origin “标签名称”
Master: V1.0 V2.0
Dev: b1.0 b2.0
git clone -b 标签、分支 https/git
“`

## 14 代码仓库

“`sh
公共仓库:gitee.com/github.com
私有仓库:gitlab,gogs

在gitee上新建仓库
“`

## 15 创建仓库

1 gitee上新建仓库

![image-20250328153432739](D:\Program Files (x86)\Typora\综合架构-git\image-20250328153432739.png)

![image-20250329094701933](D:\Program Files (x86)\Typora\综合架构-git\image-20250329094701933.png)

2 连接远程仓库-秘钥方式

“`sh
创建密钥对
Administrator@ysl MINGW64 ~
$ ssh-keygen.exe
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_ed25519):
Enter passphrase for “/c/Users/Administrator/.ssh/id_ed25519” (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_ed25519
Your public key has been saved in /c/Users/Administrator/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:u2NAfeAyRbguOfff3gThJRRJvGKvpFGiFK2zcz2rDOk Administrator@ysl
The key’s randomart image is:
+–[ED25519 256]–+
| +. o+o |
| o + .o |
| B . o.. |
| O + =..+ |
| = *S* oo |
| + B.o.+ .. |
| +o=.+ + . |
| . o=.o. o |
| E.++..o . |
+—-[SHA256]—–+

Administrator@ysl MINGW64 ~

“`

![image-20250329100302219](D:\Program Files (x86)\Typora\综合架构-git\image-20250329100302219.png)

3 在远程仓库中配置公钥

![image-20250329095101378](D:\Program Files (x86)\Typora\综合架构-git\image-20250329095101378.png)

![image-20250329095309854](D:\Program Files (x86)\Typora\综合架构-git\image-20250329095309854.png)

![image-20250329100436201](D:\Program Files (x86)\Typora\综合架构-git\image-20250329100436201.png)

![image-20250329100957035](D:\Program Files (x86)\Typora\综合架构-git\image-20250329100957035.png)

“`sh
[root@devops-gitlab /app/src/bugc-live]# git config –global user.name “yangsenlin”
[root@devops-gitlab /app/src/bugc-live]# git config –global user.email “15640879+ysllxl@user.noreply.gitee.com”
[root@devops-gitlab /app/src/bugc-live]# mkdir ysl-live
[root@devops-gitlab /app/src/bugc-live]# cd ysl-live
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git init
Initialized empty Git repository in /app/src/bugc-live/ysl-live/.git/
[root@devops-gitlab /app/src/bugc-live/ysl-live]# touch README.md
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git add README.md
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git commit -m “first commit”
[master (root-commit) 58a2ad5] first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git remote add origin git@gitee.com:ysllxl/ysl-live.git
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git push -u origin –all
The authenticity of host ‘gitee.com (180.76.199.13)’ can’t be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added ‘gitee.com,180.76.199.13’ (ECDSA) to the list of known hosts.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 225 bytes | 225.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 5e49a6b3
To gitee.com:ysllxl/ysl-live.git
* [new branch] master -> master
Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’.
[root@devops-gitlab /app/src/bugc-live/ysl-live]#
“`

“`sh
执行命令后刷新页面,查看
“`

![image-20250329101111837](D:\Program Files (x86)\Typora\综合架构-git\image-20250329101111837.png)

4 新建代码并上传

“`sh
[root@devops-gitlab /app/src/bugc-live/ysl-live]# touch gitee-code-test.txt
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git add .
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git commit -m ‘gitee-code-upload-test’
[master 2b81168] gitee-code-upload-test
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 gitee-code-test.txt
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git tag -m “gitee-code-upload-test” -a “v2.0”
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git push -u origin master
Warning: Permanently added the ECDSA host key for IP address ‘180.76.198.77’ to the list of known hosts.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 278 bytes | 278.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 754aab8f
To gitee.com:ysllxl/ysl-live.git
58a2ad5..2b81168 master -> master
Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’.
[root@devops-gitlab /app/src/bugc-live/ysl-live]# git push -u origin –tags
Warning: Permanently added the ECDSA host key for IP address ‘180.76.198.225’ to the list of known hosts.
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 182 bytes | 182.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag fb47f59d
To gitee.com:ysllxl/ysl-live.git
* [new tag] v2.0 -> v2.0
“`

![image-20250329101650381](D:\Program Files (x86)\Typora\综合架构-git\image-20250329101650381.png)

![image-20250329101744758](D:\Program Files (x86)\Typora\综合架构-git\image-20250329101744758.png)

5 git远程仓库命令

“`sh
git远程仓库:
1.配置与远程仓库的认证
ssh√√√√√: 需要将服务器的公钥推送到指定用户下;
https:(私有) 需要有用户名称,密码,每次都需要输入;
2.添加远程仓库:
添加add
git remote add origin [https://或者git(ssh)]
删除remove
git remote remove orgin 即可
改名
git remove rename origin bak
3.将本地的仓库内容,推送到远程仓库:
git add .
git commit -m “Messages”
git push -u origin branch (分支名字) [
master | …. ]
git pull origin branch(分支名字)
4.如果有新员工加入
指定仓库的代码都下载。
git clone [https://|git]
git push origin 分支名字
git pull origin –tag
“`

6 git基础命令

“`sh
1. `git clone`
– 含义:克隆一个远程仓库到本地。
– 用途:当你想要获取一个项目的完整副本时使用。它会创建一个新的本地仓库目录,并将远程仓库中的所有分支和历史记录都拉取到本地。
– 示例:`git clone https://github.com/user/repo.git`,将远程仓库克隆到本地当前目录下的 `repo` 文件夹。

2. `git add`
– 含义:将文件添加到暂存区(staging area)。
– 用途:在提交之前,需要先将文件的更改添加到暂存区。只有暂存区的文件会在下一次提交时被记录。
– 示例:
– `git add file.txt`:将 `file.txt` 添加到暂存区。
– `git add .`:将当前目录下所有更改的文件添加到暂存区。
– `git add -A`:将所有更改(包括新文件、修改文件和删除文件)添加到暂存区。

3. `git commit`
– 含义:将暂存区的更改提交到本地仓库。
– 用途:保存当前工作状态,记录更改的历史信息。
– 示例:
– `git commit -m “描述信息”`:提交暂存区的更改,并添加描述信息。
– `git commit -am “描述信息”`:直接提交所有已跟踪文件的更改(跳过暂存区)。

4. `git push`
– 含义:将本地分支的更改推送到远程仓库。
– 用途:将本地提交的更改同步到远程仓库,供其他开发者使用。
– 示例:
– `git push origin branch_name`:将本地分支 `branch_name` 推送到远程仓库的同名分支。
– `git push -u origin branch_name`:推送的同时设置上游分支(后续可以直接用 `git push` 推送该分支)。

5. `git pull`
– 含义:从远程仓库拉取最新的更改,并合并到当前分支。
– 用途:更新本地分支,使其与远程分支保持一致。
– 示例:
– `git pull origin branch_name`:从远程仓库的 `branch_name` 拉取更改并合并到当前分支。

6. `git fetch`
– 含义:从远程仓库拉取最新的更改,但不自动合并到当前分支。
– 用途:查看远程仓库的最新状态,而不影响本地工作区。通常与 `git merge` 或 `git rebase` 结合使用。
– 示例:
– `git fetch origin`:从远程仓库 `origin` 拉取最新更改。

7. `git merge`
– 含义:将一个分支的更改合并到当前分支。
– 用途:用于整合不同分支的代码。
– 示例:
– `git merge branch_name`:将 `branch_name` 分支的更改合并到当前分支。

8. `git log`
– 含义:查看提交历史记录。
– 用途:用于了解项目的开发历程,查看每次提交的详细信息。
– 示例:
– `git log`:显示完整的提交历史。
– `git log -p`:显示每次提交的详细更改。
– `git log –oneline`:以简洁的单行格式显示提交历史。

9. `git reflog`
– 含义:查看本地仓库的引用日志,记录了所有分支和HEAD的移动历史。
– 用途:用于恢复误操作(如丢失的提交或错误的重置)。
– 示例:
– `git reflog`:显示引用日志。

10. `git status`
– 含义:查看当前工作区和暂存区的状态。
– 用途:了解哪些文件被修改、哪些文件已暂存等。
– 示例:
– `git status`:显示当前工作区和暂存区的状态。

11. `git branch`
– 含义:管理分支。
– 用途:创建、删除、查看分支。
– 示例:
– `git branch`:列出所有本地分支。
– `git branch branch_name`:创建新分支。
– `git branch -d branch_name`:删除分支。

12. `git checkout`
– 含义:切换分支或检出文件。
– 用途:用于切换到其他分支,或者恢复文件到某个版本。
– 示例:
– `git checkout branch_name`:切换到指定分支。
– `git checkout file.txt`:恢复工作区的 `file.txt` 到最近一次提交的状态。

13. `git merge`
– 含义:合并分支。
– 用途:将一个分支的更改合并到当前分支。
– 示例:
– `git merge branch_name`:将 `branch_name` 分支的更改合并到当前分支。

14. `git reset –hard`
– 含义:重置当前分支到指定的提交。
– 用途:用于撤销本地更改,将工作区和暂存区恢复到指定的提交状态。
– 示例:
– `git reset –hard HEAD`:撤销所有暂存区和工作区的更改。
– `git reset –hard commit_id`:将当前分支重置到指定的提交。

15. `git remote add origin`
– 含义:添加远程仓库的地址。
– 用途:设置本地仓库与远程仓库的关联。
– 示例:
– `git remote add origin https://github.com/user/repo.git`:将远程仓库地址添加为 `origin`。

16. `git tag`
– 含义:创建标签。
– 用途:用于标记特定的提交,通常用于版本发布。
– 示例:
– `git tag v1.0`:在当前提交创建标签 `v1.0`。
– `git tag -a v1.0 -m “Release version 1.0″`:创建带注释的标签。

这些命令是 Git 的基础操作,掌握它们可以帮助你高效地管理代码版本和协作开发。
“`

# gitlab

## 1 概述

“`sh
gitlab是私有代码仓库
特点:
1 精细化权限配置,让系统更安全
2 控制用户/用户组是否可以提交到主分支(PR Push Request)
3 它使用Ruby语言写成。后来,一些部分用Go语言重写
“`

## 2 gitlab和github/gitee的关系

| | gitlab | github/gitee |
| —— | ————————————————– | —————————————— |
| 共同点 | 存放代码,git访问 | 存放代码,git访问 |
| 不同点 | 精确化控制权限、全面安全措施、定时备份、升级、迁移 | 使用权限,用户管理比较弱,无法做到精细化权限 |

## 3 应用场景

“`sh
1 开源免费,搭建简单,维护成本低符合中小公司口味 gogs.io
2 权限管理,实现代码对部分人可见,安全性高
3 离线同步
1 #gogs
https://gogs.io/docs/installation/install_from_binary
https://blog.mynook.info/post/host-your-own-git-server-using-gogs/
“`

## 4 架构

![image-20250329103812969](D:\Program Files (x86)\Typora\综合架构-git\image-20250329103812969.png)

![image-20250329103937720](D:\Program Files (x86)\Typora\综合架构-git\image-20250329103937720.png)

![image-20250329104214465](D:\Program Files (x86)\Typora\综合架构-git\image-20250329104214465.png)

“`sh
官网说明
https://docs.gitlab.com/development/architecture/#components
“`

## 5 部署gitlab

“`sh
1 下载安装
[root@devops-gitlab ~]# yum install -y policycoreutils-python-utils.noarch

[root@devops-gitlab ~]# wget https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-15.9.3-ce.0.el7.x86_64.rpm/download.rpm

[root@devops-gitlab ~]# rpm -ivh –nodeps gitlab-ce-15.9.3-ce.0.el7.x86_64.rpm

2 修改配置文件
[root@devops-gitlab ~]# cp /etc/gitlab/gitlab.rb{,.bak}
[root@devops-gitlab ~]# cat > /etc/gitlab/gitlab.rb<> /etc/hosts
[root@devops-gitlab /app/src/bugc-live]# cat /etc/hosts

3 再次检查git
[root@devops-gitlab /app/src/bugc-live]# git remote -v
gitee git@gitee.com:ysllxl/ysl-live.git (fetch)
gitee git@gitee.com:ysllxl/ysl-live.git (push)
origin http://gitlab.ysl.cn/gitlab-instance-3d7cae8e/test_gitlab.git (fetch)
origin http://gitlab.ysl.cn/gitlab-instance-3d7cae8e/test_gitlab.git (push)

4 查看状态
[root@devops-gitlab /app/src/bugc-live]# git status

5 上传代码,标签
[root@devops-gitlab /app/src/bugc-live]# git push -u origin –all
Username for ‘http://gitlab.ysl.cn’: root
Password for ‘http://root@gitlab.ysl.cn’:
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 2 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (12/12), 984 bytes | 984.00 KiB/s, done.
Total 12 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for master, visit:
remote: http://gitlab.ysl.cn/gitlab-instance-3d7cae8e/test_gitlab/-/merge_requests/new?merge_request%5Bsource_branch%5D=master
remote:
remote:
remote: To create a merge request for shopping, visit:
remote: http://gitlab.ysl.cn/gitlab-instance-3d7cae8e/test_gitlab/-/merge_requests/new?merge_request%5Bsource_branch%5D=shopping
remote:
To http://gitlab.ysl.cn/gitlab-instance-3d7cae8e/test_gitlab.git
* [new branch] master -> master
* [new branch] shopping -> shopping
Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’.
Branch ‘shopping’ set up to track remote branch ‘shopping’ from ‘origin’.

[root@devops-gitlab /app/src/bugc-live]# git push -u origin –tags
Username for ‘http://gitlab.ysl.cn’: root
Password for ‘http://root@gitlab.ysl.cn’:
Everything up-to-date
“`

![image-20250330220036034](D:\Program Files (x86)\Typora\综合架构-git\image-20250330220036034.png)

“`sh
6 新建一个标签并上传
[root@devops-gitlab /app/src/bugc-live]# echo test_live_shopping > readme.md
[root@devops-gitlab /app/src/bugc-live]# git add .

[root@devops-gitlab /app/src/bugc-live]# git commit -m “add readme”
[master 252825f] add readme
2 files changed, 2 insertions(+)
create mode 100644 readme.md
create mode 160000 ysl-live
[root@devops-gitlab /app/src/bugc-live]# git push -u origin –all
Username for ‘http://gitlab.ysl.cn’: root
Password for ‘http://root@gitlab.ysl.cn’:
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 377 bytes | 377.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for master, visit:
remote: http://gitlab.ysl.cn/gitlab-instance-3d7cae8e/test_gitlab/-/merge_requests/new?merge_request%5Bsource_branch%5D=master
remote:
To http://gitlab.ysl.cn/gitlab-instance-3d7cae8e/test_gitlab.git
ac51a20..252825f master -> master
Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’.
Branch ‘shopping’ set up to track remote branch ‘shopping’ from ‘origin’.
“`

![image-20250330220825580](D:\Program Files (x86)\Typora\综合架构-git\image-20250330220825580.png)

## 8 gitlab备份与恢复

“`sh
1 修改配置文件
在/etc/gitlab/gitlab.rb增加
#开启备份功能
gitlab_rails[‘manage_backup_path’] = true
#备份目录
gitlab_rails[‘backup_path’] = “/var/opt/gitlab/backups”
#备份文件权限
gitlab_rails[‘backup_archive_permissions’] = 0600
#备份保留时间
gitlab_rails[‘backup_keep_time’] = 604800

2 reconfigure一下
[root@devops-gitlab /app/src/bugc-live]# gitlab-ctl reconfigure

3 开始备份
[root@devops-gitlab /app/src/bugc-live]# gitlab-backup create

[root@devops-gitlab /app/src/bugc-live]# ll /var/opt/gitlab/backups/
total 452
-rw-r–r– 1 git git 460800 Mar 30 22:15 1743344106_2025_03_30_15.9.3_gitlab_backup.tar

4 恢复
gitlab-ctl stop sidekiq
gitlab-backup restore BACKUP= 1743344106_2023_03_30_15.9.3_gitlab_backup.tar
“`

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注