git - GitLab 和 LFS 推送缺少文件
问题描述
我一直在使用一个非常旧的存储库,并且在某些时候一些 LFS 文件丢失了。其中不少。当我尝试在 Gitlab 中推送到新存储库时,出现以下错误
GitLab: LFS objects are missing. Ensure LFS is properly set up or try a manual
git-lfs 的其他 QA(here,here)表明通常有一些变体,git lfs push --all
但我不再有这些文件的工作仓库,它们已经永远消失了。Gitlab 忽略使用 --no-verify 推送,仍然给出错误。
运行git lfs fetch --all
会给出一个冗长的丢失 OID 列表
[43cb9e6d1d15bb8d31af911aa69a15a67174c5df73dabc85294ce08198cac468] Object does not exist on the server or you don't have permissions to access it: [404] Object does not exist on the server or you don't have permissions to access it
[454907d530534af9cc95903820c0a632a851b45de98ba18e1de117b8a649f8ac] Object does not exist on the server or you don't have permissions to access it: [404] Object does not exist on the server or you don't have permissions to access it
[ce1314f0c4cb05f349540fa144d33faeb2281ae552cf75dc866a8350d90fd2ac] Object does not exist on the server or you don't have permissions to access it: [404] Object does not exist on the server or you don't have permissions to access it
[d5e8925d273cb00341f00d0f40b39f97cced1e833ef687de2d4663836e7f4e45] Object does not exist on the server or you don't have permissions to access it: [404] Object does not exist on the server or you don't have permissions to access it
...
此处的另一篇文章包含通过检查每个提交和弄脏 LFS 文件来完全删除 LFS 的脚本,但这似乎对存储库的前进非常不利。还有一个表示完全删除 LFS 文件的路径(此处)。
所有这些问题似乎都不是最理想的:
- 无论如何,删除 LFS 会使 repo 严重膨胀,并且对于已经损坏的文件,涂抹可能会失败
- Git pull/push -all 不是一个选项,因为文件已经消失了
- 删除 LFS 是不对的,因为文件的一个版本今天存在,只是过去某个分支中的对象丢失了,所以所有关于如何删除 LFS 的说明都会破坏 repo。
有没有办法让 GitLab 不忽略 no-verify 或有效地从历史中过滤掉特定的 OID?我不介意文件是否永远丢失,但我希望保留历史。
我知道我可以运行git log --all -p -S 43cb9e6d1d15bb8d31af911aa69a15a67174c5df73dabc85294ce08198cac468
来获取提交和文件(虽然运行 PER OID 需要 5-10 分钟,所以这需要很多小时),但我不知道该怎么做。
解决方案
我刚刚通过以下步骤解决了同样的问题:
- 我已经得到了脏文件的相对路径
git lfs ls-files
。 - 我在https://rtyley.github.io/bfg-repo-cleaner/下载了 BFG Repo Cleaner
- 我运行 bfg 传递参数
--delete-files <DIRTY_FILE_PATH>
BFG 日志向我报告了以下警告:
Protected commits
-----------------
These are your protected commits, and so their contents will NOT be altered:
* commit 9edf1837 (protected by 'HEAD') - contains 1 dirty file :
- requirements/LMD-SE-10-D11/setupse10d11.exe (132 B )
WARNING: The dirty content above may be removed from other commits, but as
the *protected* commits still use it, it will STILL exist in your repository.
Details of protected dirty content have been recorded here :
<REPO_PATH>/..bfg-report/2021-07-30/14-12-39/protected-dirt/
If you *really* want this content gone, make a manual commit that removes it,
and then run the BFG on a fresh copy of your repo.
为了处理这个阻止我删除脏文件的警告,我再次克隆了 repo,但没有镜像它。
现在,按照日志的建议,我通过提交删除了脏文件,并使用相同的参数再次运行 BFG 命令。
最后,我发出了命令:
git reflog expire --expire=now --all
git gc --prune=now --aggressive
并强行改写历史git push --force
。
结果:脏 LFS 引用终于消失了!
推荐阅读
- reactjs - 反应选择多行标签
- sql-server - 列别名而不是技术名称
- python-2.7 - 获取父标签Selenium Python的元素
- reactjs - React Router v3 - IndexRoute 在 Google 缓存中不起作用
- gremlin - Gremlin 顺序模式和使用循环的边缘更新
- javascript - 页面切换脚本问题
- angular - Angular Material 6 datepicker 的关闭按钮可防止视图更新
- linux - qtCreator,找不到可执行文件
- ios - 如何将数据传回堆栈中的视图控制器?
- methods - 将方法数据返回给另一个方法不好吗?