首页 > 解决方案 > 在新的 gitlab 存储库中,我收到此错误:LFS 对象丢失。确保正确设置 LFS 或尝试手动“git lfs push --all”

问题描述

我刚刚在该组中建立了一个新的 gitlab 组和一个新的私有 gitlab 存储库。我正在尝试从现有文件夹创建一个项目。

问题

我从现有文件夹中删除了包含所有 git 历史记录的 .git 文件夹。然后我创建了gitlab存储库,执行

git init
git remote add origin git@gitlab.com:my_group_username/my-repo.git
git add .
git commit -m "initial commit"
git push origin master

我收到了这个错误:

 ! [remote rejected] master -> master (pre-receive hook declined)

我试过的

git config list

并且我的用户信息已按预期配置。

任何想法可能导致此错误?

编辑 - git push 命令和输出:

git push -u origin --all
Enumerating objects: 31, done.
Counting objects: 100% (31/31), done.
Delta compression using up to 12 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (31/31), 78.73 KiB | 8.75 MiB/s, done.
Total 31 (delta 0), reused 0 (delta 0)
remote: GitLab: LFS objects are missing. Ensure LFS is properly set up or try a manual "git lfs push --all".
To gitlab.com:dellacortelab/prospr.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gitlab.com:dellacortelab/prospr.git'

再看一遍,LFS(大文件存储)似乎有问题,但存储库的大小只有 1.5 Mb。它原本确实有一些大文件,但我在删除 .git 文件夹之前删除了它们,所以我不知道 gitlab 是如何知道它们的。

更新:

我的 .gitattributes 文件中有对 LFS 文件的引用,所以我删除了 .gitattributes 文件及其引用的目录,但我仍然遇到同样的错误。

删除 .gitattributes 文件:

potts/plmDCA_asymmetric/plmDCA_asymmetric.ctf filter=lfs diff=lfs merge=lfs -text

标签: gitgitlab

解决方案


最终解决方案:从 git 历史记录中清除所有对 LFS 文件的引用

  • 我删除了该.gitattributes文件以及它引用的文件:potts/plmDCA_asymmetric/plmDCA_asymmetric.ctf,然后再次提交。
  • 还是推不开
  • 所以我删除了.git目录,重新初始化了 git 存储库,然后推送。
  • 有效!

可能有更细微的方法来清除引用 LFS 的 git 历史记录,但这很有效。


推荐阅读