![](/img/trans.png)
[英]How to reduce git repository storage after migrating git repository to git lfs?
[英]Removing missing LFS objects from git repository
我在客户端和服务器上的 git 存储库*中缺少一堆 LFS 对象。 我知道这些对象丢失了,没关系。 不幸的是,这意味着git lfs fetch --all
甚至git lfs push --all origin
将失败。
我想通过用虚拟文本文件替换二进制文件或完全删除指针来从存储库中清除“损坏的指针”。 我也知道这涉及重写历史,这也很好。
最好的方法是什么?
*澄清一下,我遗漏了服务器上的一些LFS 文件,但不是所有文件,也不是这些文件的所有修订版。
例如,我有 foo.png 已在 3 次提交中修改:
LFS 服务器不再有 foo.png 版本 2,所以我想从历史记录中删除该提交。 不幸的是 git lfs 并没有告诉我哪个提交被破坏,它只是告诉我661f0797
丢失了。
(作为记录,我找到了丢失的文件,所以我不再有这个问题,但解决方案应该仍然很有趣!)
如果您仍在寻找一种方法来查看哪些提交受到影响,请获取缺少的 LFS 对象 ID 并使用此命令查找提交:
git log --source --all -p -S <LFS-OBJ-ID>
您可以untrack
文件, 手册在这里。
只有一个文件:
git lfs untrack "/path/to/my-file.gif"
使用通配符,您可以通过一个命令捕获多个文件:
git lfs untrack "*.gif"
这个脚本对我有用——它删除了所有看起来像 LFS 文件的 blob。
git filter-repo --force --blob-callback "
if blob.data.split(b'\n', 1)[0] == b'version https://git-lfs.github.com/spec/v1':
blob.skip()
"
您是否尝试过简单的(建议在使用以下命令之前进行备份):
rm -f .git/index
git reset
使 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.