在 Linux 上的 GitLab 中“恢复仓库”要分几种场景,不同情况做法完全不同。下面按常见情况说明:
如果是通过 Web 页面删除项目:
⚠️ 默认保留 7 天或 30 天(取决于配置)
如果你有 GitLab 备份:
# 停止相关服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 恢复备份
gitlab-rake gitlab:backup:restore BACKUP=备份时间戳
# 启动
gitlab-ctl start
备份文件一般在:
/var/opt/gitlab/backups/
如果你或其他人还有本地仓库:
cd /var/opt/gitlab/git-data/repositories/<group>/<project>.git
rm -rf *
git clone --bare /本地仓库路径 .
或:
git push --mirror git@gitlab:group/project.git
git reflog
git checkout <commit>
git branch recovery
如果有人本地还有:
git push origin recovery
⚠️ 很难恢复 可尝试:
git fsck 修复裸仓库为了给你精确命令,请告诉我:
gitlab-rake gitlab:env:info)我可以一步步带你操作。