如何删除 git-lfs 跟踪的文件并释放存储配额?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34579211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:39:53  来源:igfitidea点击:

How to delete a file tracked by git-lfs and release the storage quota?

gitgithubgit-lfs

提问by lucemia

How to delete a never-use-again file and release the storage back to the github lfs quota?

如何删除不再使用的文件并将存储释放回 github lfs 配额?

Does deleting the reference point of the file in git history work in this situation?

在这种情况下,删除 git history 中文件的参考点是否有效?

采纳答案by Wader

There doesn't currently appear to be a great way of removing large assets from git-lfs. GitHub's current suggestion is to use a tool called The BFGto completely strip all existence of the file from your repo.

目前似乎没有一种很好的方法可以从git-lfs. GitHub 当前的建议是使用一个名为The BFG的工具从您的 repo 中完全删除该文件的所有存在。

Presumably it'll then be removed from the lfs storage when git's garbage collection is next run by GitHub.

据推测,当 GitHub 下次运行 git 的垃圾收集时,它将从 lfs 存储中删除。

For more info see https://help.github.com/en/github/managing-large-files/removing-files-from-git-large-file-storage

有关更多信息,请参阅https://help.github.com/en/github/managing-large-files/removing-files-from-git-large-file-storage

Edit 2019-11-20

编辑 2019-11-20

GitHub have updated their documentation on this explicitly stating there is no way to free up your git-lfs storage without deleting your repository. https://help.github.com/en/github/managing-large-files/removing-files-from-git-large-file-storage

GitHub 已经更新了他们的文档,明确指出在不删除存储库的情况下无法释放 git-lfs 存储空间。https://help.github.com/en/github/managing-large-files/removing-files-from-git-large-file-storage

Their only recommendation is to still use the BFG tool to strip the file from your repository, which will reduce the size of your repository when cloning, but will still count towards your git-lfs quota until you delete the repository.

他们唯一的建议是仍然使用 BFG 工具从您的存储库中删除文件,这将在克隆时减少存储库的大小,但在您删除存储库之前仍将计入您的 git-lfs 配额。

GitLab again suggest using the BFG tool and will automatically clean the lfs storage of any files which aren't referenced in any commits, although currently this doesn't seem to be working correctly. Thisissue has been open since 2017 with no resolution.

GitLab 再次建议使用 BFG 工具,并将自动清理任何提交中未引用的任何文件的 lfs 存储,尽管目前这似乎无法正常工作。问题自 2017 年以来一直未解决,一直没有解决。

BitBucket have a section in the repository settings which you can clean up lfs files. https://www.atlassian.com/git/tutorials/git-lfs#deleting-remote-files

BitBucket 在存储库设置中有一个部分,您可以清理 lfs 文件。https://www.atlassian.com/git/tutorials/git-lfs#deleting-remote-files

回答by Chris

The answer given by Wader is not related to the question.

韦德给出的答案与问题无关。

The given link to a github article is about large files directly checked into the git repo, which is NOT the same as git-lfs!

给定的 github 文章链接是关于直接签入 git repo 的大文件,这与 git-lfs 不同!

As for the question: how this situation is handled depends on the underlying storage server. git-lfs support can be provided by different services, e.g. GitHub oder GitLab.

至于问题:这种情况如何处理取决于底层存储服务器。git-lfs 支持可以由不同的服务提供,例如 GitHub 或 GitLab。

GitLab stores git-lfs files not per repository. They are stored by their SHA-256 hash value. If the same file is used in several repositories (e.g clones), it is only stored once. It solely depends on GitLab how it handles referenced files and should be looked up in the manual.

GitLab 存储 git-lfs 文件而不是每个存储库。它们由其 SHA-256 哈希值存储。如果同一个文件在多个存储库(例如克隆)中使用,则它只存储一次。它完全取决于 GitLab 如何处理引用的文件,应该在手册中查找。

According to GitHubs documentation (https://help.github.com/articles/removing-files-from-git-large-file-storage/), it is recommended to delete and recreate a repository: "To remove Git LFS objects from a repository, delete and recreate the repository. When you delete a repository, any associated issues, stars, and forks are also deleted."

根据 GitHubs 文档(https://help.github.com/articles/removing-files-from-git-large-file-storage/),建议删除并重新创建存储库:“To remove Git LFS objects from一个存储库,删除并重新创建存储库。当你删除一个存储库时,任何相关的问题、星标和分叉也会被删除。”

回答by Brandt

The answer given by Chris is not accurate; combined with the comment from 0xcaff ("that's a terrible solution"), it may mislead the inexperient user (or distracted reader).

克里斯给出的答案并不准确;结合 0xcaff 的评论(“这是一个糟糕的解决方案”),它可能会误导没有经验的用户(或分心的读者)。

The right answer is a mixture of Wader's and Chris'.

正确答案是韦德和克里斯的混合体。

I just solved a case where I wanted to mirror a repository (let's call it REPO-1) that once upon a timeused LFS, but has not been history-cleaned from the large files.

我刚刚解决了一个案例,我想镜像一个曾经使用过 LFS的存储库(让我们称之为REPO-1),但尚未从大文件中清除历史记录。

At some moment in the last month I removed support for LFS in REPO-1with git lfs uninstall. And that was working fine for subsequent git clones (i.e., no git-lfsanymore). But today when I tried to pulla previously push --mirrorversion of REPO-1I got messages Smudge error: Error downloading <big-filename> ... Object does not exist on the server: [404] Object does not exist on the server

在上个月有的时候我删除在LFS支持REPO-1git lfs uninstall。这对后续的git clones工作正常(git-lfs不再)。但是今天当我尝试pull使用以前的push --mirror版本时REPO-1我收到了消息Smudge error: Error downloading <big-filename> ... Object does not exist on the server: [404] Object does not exist on the server

So, if you want to get rid of LFS and any reference to the once-tracked files you have to:

因此,如果您想摆脱 LFS 和对曾经跟踪过的文件的任何引用,您必须:

  1. uninstall LFS from the repo;
  2. clean the repo's history;
  3. delete (or rename) the old (github) repo, create a new one and push the cleaned repo into it.
  1. 从 repo 中卸载 LFS;
  2. 清理 repo 的历史记录;
  3. 删除(或重命名)旧的(github)存储库,创建一个新存储库并将清理过的存储库推入其中。

1

1

To uninstallLFS is a simple command like git lfs uninstallwill do it.

卸载LFS是一个简单的命令一样git的LFS卸载将做到这一点。

2

2

To clean the repo's history is a bit scary, but works just fine with git filter-branch, item 3of the Github docs --https://help.github.com/en/articles/removing-sensitive-data-from-a-repository-- should be about enough:

要清洁回购的历史是一个有点吓人,但工作得很好用git filter-branch,项目3GitHub的文档的- https://help.github.com/en/articles/removing-sensitive-data-from-a-repository- - 应该足够了:

$ git filter-branch --force --index-filter \
      "git rm --cached --ignore-unmatch FILENAME-1 FILENAME-2 FILENAME-3" \
      --prune-empty --tag-name-filter cat -- --all

3

3

The deletion and re-creation of the repository is not as destructive at seems like, remember that your local repository is completely independent, self-sustained cloneof what's in Github. When you push the your local (clean) version to the new, blank repository it will be like that (deletion/creation) never happened.

存储库的删除和重新创建并不像看起来那样具有破坏性,请记住,您的本地存储库是完全独立的、自我维持的 Github克隆。当您将本地(干净)版本推送到新的空白存储库时,它就像(删除/创建)从未发生过一样。