首页 > 解决方案 > GitLab 和 LFS 推送缺少文件

问题描述

我一直在使用一个非常旧的存储库,并且在某些时候一些 LFS 文件丢失了。其中不少。当我尝试在 Gitlab 中推送到新存储库时,出现以下错误

 GitLab: LFS objects are missing. Ensure LFS is properly set up or try a manual 

git-lfs 的其他 QA(herehere)表明通常有一些变体,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 文件的路径(此处)。

所有这些问题似乎都不是最理想的:

  1. 无论如何,删除 LFS 会使 repo 严重膨胀,并且对于已经损坏的文件,涂抹可能会失败
  2. Git pull/push -all 不是一个选项,因为文件已经消失了
  3. 删除 LFS 是不对的,因为文件的一个版本今天存在,只是过去某个分支中的对象丢失了,所以所有关于如何删除 LFS 的说明都会破坏 repo。

有没有办法让 GitLab 不忽略 no-verify 或有效地从历史中过滤掉特定的 OID?我不介意文件是否永远丢失,但我希望保留历史。

我知道我可以运行git log --all -p -S 43cb9e6d1d15bb8d31af911aa69a15a67174c5df73dabc85294ce08198cac468来获取提交和文件(虽然运行 PER OID 需要 5-10 分钟,所以这需要很多小时),但我不知道该怎么做。

标签: gitgitlabgit-lfs

解决方案


我刚刚通过以下步骤解决了同样的问题:

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 引用终于消失了!


推荐阅读