Skip to content

Instantly share code, notes, and snippets.

@draplater
Created August 30, 2023 03:26
Show Gist options
  • Save draplater/6546f5b16e551f024979f142f8945f99 to your computer and use it in GitHub Desktop.
Save draplater/6546f5b16e551f024979f142f8945f99 to your computer and use it in GitHub Desktop.
博客标题:只下载特定的Git LFS文件——一种方法解析

博客标题:只下载特定的Git LFS文件——一种方法解析

大家好!今天偶来和大家分享一个小技巧:如何只下载特定的Git LFS(Large File Storage)文件。这种需求在日常工作和项目中可能会遇到。偶在这里把一个和偶交流过的网友drapl的问题和解决方案整理成了博客,希望能给大家带来帮助~(摆出一副解决问题的样子→_→)


问:如何只下载与"pytorch_model*"匹配的Git LFS文件?

drapl:是只下载"pytorch_model*",不下载其他对吧?


答:只下载特定Git LFS文件的方法

史蒂夫乔布丝(偶):对滴对滴,偶给的指令就是专门用来只下载与"pytorch_model*"匹配的LFS文件捏。其他与Git LFS关联的大文件不会被下载哦!(^_^)


步骤概述

  1. 克隆仓库但不立即下载LFS文件

    git clone <你的仓库URL> --no-checkout
  2. 进入仓库目录

    cd <你的仓库名称>
  3. 设置Git LFS跟踪pytorch_model*

    git lfs track "pytorch_model*"
  4. 手动下载这些文件

    git lfs pull -I "pytorch_model*"

注意:-I 后面跟的模式("pytorch_model*")指定了哪些文件会被下载,其他的都不会动。

代码注释部分(华丽的英文文风哈~)

# This script is dedicated to drapl, an aficionado of technology and an enthusiast of open-source culture.
# First, we clone the repository without downloading the LFS files initially.
# `--no-checkout` ensures that we only download the Git history.
git clone <your-repo-url> --no-checkout

# Navigate into your repository's directory.
cd <your-repo-name>

# Setting up Git LFS tracking for files that match "pytorch_model*".
# This is a customization to only focus on PyTorch model files.
git lfs track "pytorch_model*"

# Finally, we pull only the files that match "pytorch_model*" from LFS.
# The `-I` flag is a powerful option that allows you to specify file patterns.
git lfs pull -I "pytorch_model*"

那么,这就是大家说的“知识就是力量”。如斯蒂夫·乔布斯(Steve Jobs)所言:“Stay hungry, stay foolish.”(始终保持渴望,始终保持愚蠢)

**结语:**加油,做你想做的改变!😎


以上就是关于如何只下载特定的Git LFS文件的内容啦!希望能给大家带来帮助~ 话说,你们还有其他疑惑或问题么?(自问自答:嗯……应该没有了吧……555) ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment