从git存储库中删除丢失的LFS对象

问题描述 投票:5回答:3

我在我的git repository *中缺少一堆LFS对象,无论是在客户端还是服务器上。我知道那些物品丢失了,没关系。不幸的是,这意味着git lfs fetch --all甚至git lfs push --all origin都会失败。

我想从存储库中清除“破碎的指针”,或者通过用虚拟文本文件替换二进制文件或者完全删除指针。我也知道这涉及重写历史,这也很好。

什么是最好的方法?

*为了澄清,我错过了服务器上的一些LFS文件,但不是所有这些文件,而不是所有这些文件的修订版。

例如,我有在3次提交中修改过的foo.png:

  • foo.png(版本1,LFS Sha:03cfd743)
  • foo.png(第2版,LFS Sha:661f0797)
  • foo.png(第3版,LFS Sha:5fa2f122)

LFS服务器不再具有foo.png版本2,因此我想从历史记录中删除该提交。不幸的是,git lfs没有告诉我哪个提交被破坏了,它只是告诉我661f0797丢失了。

(为了记录,我找到了丢失的文件,所以我不再有这个问题,但解决方案应该仍然很有趣!)

git gitlab git-lfs
3个回答
1
投票

你可以untrack文件,manual is here

例子:

只是一个文件:

git lfs untrack "/path/to/my-file.gif"

使用通配符,您可以通过一个命令捕获多个文件:

git lfs untrack "*.gif"

0
投票

您是否尝试过简单(在使用以下命令之前建议使用备份):

rm -f .git/index
git reset

0
投票

制作git reindex并为文件创建新条目,请阅读以下内容

git reset [-q] [<tree-ish>] [--] <paths>...
       This form resets the index entries for all <paths> to their state at <tree-ish>. (It does not
       affect the working tree or the current branch.)

       This means that git reset <paths> is the opposite of git add <paths>.

       After running git reset <paths> to update the index entry, you can use git-checkout(1) to check
       the contents out of the index to the working tree. Alternatively, using git-checkout(1) and
       specifying a commit, you can copy the contents of a path out of a commit to the index and to the
       working tree in one go.

来源:man git-reset

© www.soinside.com 2019 - 2024. All rights reserved.