`git lfs fetch`、`git lfs fetch --all` 和 `git lfs pull` 之间有什么区别?

Gab*_*les 22 git git-lfs

尽管已经使用git多年,但我发现git lfsgit Large File Storage)使用起来相当混乱,即使是在非常基础的水平上。有人可以解释一下这3个命令之间的区别吗?:

  1. git lfs fetch
  2. git lfs fetch --all
  3. git lfs pull

有关的:

  1. 从 git LFS 中提取所有文件

Gab*_*les 40

经过大量研究并弄清楚帮助页面在哪里后,这就是我的结论。

但请注意,Git LFS 速度慢、效率低、在线(与离线的 Git 不同)且邪恶。请阅读我在eRCaGuy_dotfiles 存储库中的完整咆哮

git lfs基本用户如何使用

git lfs fetch这涵盖了以下问题:“ 、git lfs fetch --allgit lfs pull和之间有什么区别git lfs checkout?”

概括

# Fetch git lfs files for just the currently-checked-out branch or commit (Ex: 20
# GB of data). This downloads the files into your `.git/lfs` dir but does NOT
# update them in your working file system for the branch or commit you have 
# currently checked-out.
git lfs fetch

# Fetch git lfs files for ALL remote branches (Ex: 1000 GB of data), downloading
# all files into your `.git/lfs` directory.
git lfs fetch --all

# Fetch git lfs files for just these 3 branches (Ex: 60 GB of data)
# See `man git-lfs-fetch` for details. The example they give is:
# `git lfs fetch origin main mybranch e445b45c1c9c6282614f201b62778e4c0688b5c8`
git lfs fetch origin main mybranch1 mybranch2

# Check out, or "activate" the git lfs files for your currently-checked-out
# branch or commit, by updating all file placeholders or pointers in your
# active filesystem for the current branch with the actual files these git lfs
# placeholders point to.
git lfs checkout

# Fetch and check out in one step. This one command is the equivalent of these 2
# commands:
#       git lfs fetch
#       git lfs checkout
git lfs pull
#
# Note that `git lfs pull` is similar to how `git pull` is the equivalent
# of these 2 commands:
#       git fetch
#       git merge
Run Code Online (Sandbox Code Playgroud)

因此,检查文件一般推荐工作流程可能如下所示:gitgit lfs

git checkout main   # check out your `main` branch
git pull            # pull latest git files from the remote, for this branch
git lfs pull        # pull latest git lfs files from the remote, for this branch

# OR (exact same thing)
git checkout main   # check out your `main` branch
# (The next 2 commands replace `git pull`)
git fetch           # fetch the latest files from the remote for branch `main`
                        # into your locally-stored hidden remote-tracking branch
                        # named `origin/main`, for example
git merge           # merge the latest content (which you just fetched
                        # into your local hidden branch `origin/main`)
                        # into non-hidden branch `main`
# (The next 2 commands replace `git lfs pull`)
git lfs fetch       # fetch latest git lfs files from the remote, for this 
                        # branch
git lfs checkout    # check out all git lfs files for this branch, replacing 
                        # git lfs file placeholders with the actual files
Run Code Online (Sandbox Code Playgroud)

细节

1.git lfs fetch

参见man git-lfs-fetch、 和git lfs fetch --help

来自git lfs fetch --help(强调):

从指定的远程下载给定引用处的 Git LFS 对象。如果您不指定,请参阅“默认远程”和“默认引用”,了解会发生什么情况。

这不会更新工作副本。

因此,这就像执行操作一样git fetch(它将远程内容获取到本地存储的远程跟踪隐藏分支),只不过它是针对git lfs- 控制的文件。

我相信它将git lfs文件内容提取到您的.git/lfs目录,但不会使用这些文件更新您的活动文件系统(当前签出的分支)。

从帮助菜单的更下方(已添加重点):

默认遥控器

不带参数,从默认远程获取下载。默认远程 与 for 相同git fetch,即基于您首先跟踪的远程分支,否则基于origin

默认参考文献

如果没有给出引用作为参数,则使用当前签出的引用。此外,如果启用,还包括最近更改的引用和提交。有关详细信息,请参阅“最近更改”。

请注意,“当前签出的引用”指的是您当前签出的分支或提交。

2.git lfs fetch --all

虽然git lfs fetch仅获取当前签出分支或提交的内容,但默认情况下,git lfs fetch --all会签出所有远程分支的所有内容。在一个巨大的企业单一存储库上,这意味着git lfs fetch可能会获取20 GB的数据,而git lfs fetch --all可能会获取1000 GB的数据。在这种情况下,请勿包括,--all除非:

  1. 你绝对必须这样做,或者
  2. 获取的数据量仍然相当小,或者
  3. 您有一个运行过夜的脚本来执行此操作,并且您的硬盘驱动器足够大,可以在一夜之间获取所有内容,因此您不必在工作期间等待 Git LFS 的极其缓慢且现在在线且时间效率低下的git checkout运行小时,这会浪费您工作日的时间。欲了解更多信息。关于这一点,请参阅:
    1. 我的全部咆哮
    2. 我详细回答了git LFS 如何比 git 更有效地跟踪和存储二进制数据?[剧透:事实并非如此] ,尤其是这个答案的标题为“正常情况下什么时候git从互联网下载文件?详细了解git fetchvs git pull的部分,我在其中比较和对比了常规gitvs的在线部分git lfs

来自git lfs fetch --help(强调):

* --all

下载由作为参数提供的引用可访问的任何提交引用的所有对象。如果未提供任何引用,则将获取所有引用。这主要用于备份和迁移目的。不能与 --recent--include/组合--exclude。忽略任何全局配置的包含和排除路径以确保下载所有对象。

3.git lfs pull

就像是andgit pull的组合一样,是and的组合。git fetchgit mergegit lfs pullgit lfs fetchgit lfs checkout

来自git lfs pull --help(强调):

git lfs pull [options] [<remote>]

下载当前签出的引用的 Git LFS 对象,并根据需要使用下载的内容更新工作副本。

这相当于运行以下 2 个命令:

git lfs fetch [options] [<remote>]
git lfs checkout
Run Code Online (Sandbox Code Playgroud)

所以,这就引出了一个问题:“它git lfs checkout做什么?”:

4.git lfs checkout

此命令将git lfs文件从.git/lfs目录复制到当前已签出的当前引用(分支或提交)的活动工作树。

git lfs checkout --help

如果对象数据可用,请尝试确保工作副本包含当前引用的 Git LFS 对象的文件内容。不下载任何内容;看看git lfs fetch那个。

Checkout 扫描当前引用以查找所需的所有 LFS 对象,然后,如果工作副本中缺少文件,或者包含具有相同 SHA 的占位符指针内容,则写入真实的文件内容(前提是我们将其保存在本地)店铺。修改后的文件永远不会被覆盖。

可以提供一个或多个<glob-pattern>s 作为参数来限制更新的文件集。Glob 模式按照 中描述的格式进行匹配gitignore(5)

它提供了一些例子。前任:

例子

有关的

  1. 我的问答:git LFS 如何比 git 更高效地跟踪和存储二进制数据?[剧透:事实并非如此]
  2. 我在本节中对我的问题的解释:更新:不要使用git lfs. 我现在建议不要git lfs在我们的免费 G​​itHub 存储库中使用
  3. 我的问题,以及糟糕的解决方法不是答案的答案:如何git lfs post-checkout在失败后恢复钩子git checkout- 剧透:由于磁盘空间不足,我git lfs checkout在 3 小时内下载 27 GB 时,完成率达到 97%,一直失败。
  4. 我的答案: Unix & Linux:关于根据文件大小查找、过滤和排序的所有内容find- 请参阅末尾附近的示例,标题为“(找出要添加到git lfs下一个的文件扩展名)”
  5. 其他真正有用的 git lfs信息:
    1. 很棒的文章!:我的开发者星球:Git LFS:为什么以及如何使用
    2. https://git-lfs.github.com/
    3. 我的仓库和注释:https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles#how-to-clone-this-repo-and-all-git-submodules
    4. 非常有用的视频!:什么是 Git LFS?:https://www.youtube.com/watch ?v=9gaTargV5BY 。我从这里发现了这个视频:/sf/answers/3442114301/
  6. https://www.git-tower.com/learn/git/faq/difference- Between-git-fetch-git-pull
  7. 我对我可以“撤消”`git lfs checkout 吗?

  • @GabrielStaples 你在顶部关于不使用 git lfs 的注释非常具有误导性。您实际上建议不要在免费的 GitHub 帐户上使用 git lfs_ 。git lfs 本身并没有什么问题。 (2认同)