gpt4 book ai didi

git - 如何缩小 git LFS 存储库

转载 作者:行者123 更新时间:2023-12-03 08:49:53 26 4
gpt4 key购买 nike

在我的公司,我们使用git LFS存储系统开发相关的文件。该存储库包含 CAD 数据、图像、文档(*.pdf、*.docx、*.xlsx)等。绝对有必要将所有文件置于版本控制之下。然而,尽管 LFS 跟踪了所有文件,但存储库的使用方式最终导致存储库的总大小达到 8GB。

基本上所有内容都被推送到主分支上,这似乎使 LFS 存储变得过时,因为无法修剪任何内容来节省本地存储。

问题

有没有办法允许更多的本地对象被追溯修剪?

最佳答案

您可以使用以下命令

git lfs prune

来自docs ,

DESCRIPTION

Deletes local copies of LFS files which are old, thus freeing up disk space. Prune operates by enumerating all the locally stored objects, and then deleting any which are not referenced by at least ONE of the following:

  • the current checkout
  • a 'recent branch'; see [RECENT FILES]
  • a 'recent commit' on the current branch or recent branches; see [RECENT FILES]
  • a commit which has not been pushed; see [UNPUSHED LFS FILES]
  • any other worktree checkouts; see git-worktree(1)

In general terms, prune will delete files you're not currently using and which are not 'recent', so long as they've been pushed i.e. the local copy is not the only one.

The reflog is not considered, only commits. Therefore LFS objects that are only referenced by orphaned commits are always deleted.

Note: you should not run git lfs prune if you have different repositories sharing the same custom storage directory; see git-lfs-config(1) for more details about lfs.storage option.


由于当前 checkout 引用了 LFS 跟踪文件,因此您无法进行修剪,因此您可以使用 GIT_LFS_SKIP_SMUDGE setting 克隆没有 LFS 跟踪文件的本地存储库。

export GIT_LFS_SKIP_SMUDGE=1
git clone /path/to/local/repo test

这应该会减少存储库的大小,因为 LFS 跟踪文件将转换为指针文件。如果您想使用 LFS 跟踪文件,您需要执行 git lfs pull 。

由于 git lfs pull 将下载当前 checkout 中的所有 LFS 跟踪文件,因此您可以使用包含和排除 options包含或排除特定文件。

例如,您可以通过

将所有 pdf(LFS 跟踪文件)包含在存储库中
git lfs pull -I "*.pdf"

或通过

排除它们
git lfs pull -X "*.pdf"

请注意,您可以从远程存储库本身进行克隆,将本地存储库克隆到测试存储库只是一个示例,以显示大小已减小。

关于git - 如何缩小 git LFS 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59680238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com