温馨提示×

centos gitlab怎么回滚

小樊
36
2026-10-17 12:37:31
栏目: 智能运维

在 CentOS 上回滚 GitLab,通常分为 GitLab 应用版本回滚 和 代码仓库回滚 两种场景。下面分别说明。


一、GitLab 应用版本回滚(升级后出问题)

1️⃣ 查看已安装版本

rpm -q gitlab-ce
# 或
cat /opt/gitlab/version-manifest.txt

2️⃣ 停止 GitLab

gitlab-ctl stop

3️⃣ 安装旧版本(以 16.0.0 为例)

yum install -y gitlab-ce-16.0.0-ce.0.el7.x86_64

或从清华镜像下载:

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.0.0-ce.0.el7.x86_64.rpm
rpm -Uvh gitlab-ce-16.0.0-ce.0.el7.x86_64.rpm

4️⃣ 重新配置并启动

gitlab-ctl reconfigure
gitlab-ctl start

⚠️ 注意:

  • 跨大版本回滚风险极高(如 17 → 15)
  • 建议先备份:
gitlab-rake gitlab:backup:create

二、代码仓库回滚(Commit 回退)

场景 1:本地回滚后推送

git log
git reset --hard <commit_id>
git push --force origin branch_name

场景 2:保留历史(推荐)

git revert <commit_id>
git push origin branch_name

场景 3:GitLab Web 回滚

  1. 打开项目 → Repository → Commits
  2. 选择 commit → Options → Revert
  3. 选择目标分支

三、数据库 / 配置回滚(进阶)

如果升级失败且数据库已变更:

# 恢复备份
gitlab-rake gitlab:backup:restore BACKUP=时间戳

备份文件位置:

/var/opt/gitlab/backups/

四、安全建议

✅ 回滚前一定备份
✅ 尽量使用 revert 而非 reset
✅ 生产环境避免跨大版本回滚


如果你能告诉我:

  • GitLab 版本(升级前 / 后)
  • 是 应用崩了 还是 代码误提交
  • CentOS 版本(7 / 8)

我可以直接给你精确回滚命令。

0 踩