尽管已经使用git
多年,但我发现git lfs
(git Large File Storage)使用起来相当混乱,即使是在非常基础的水平上。有人可以解释一下这3个命令之间的区别吗?:
git lfs fetch
git lfs fetch --all
git lfs pull
有关的:
Gab*_*les 40
经过大量研究并弄清楚帮助页面在哪里后,这就是我的结论。
但请注意,Git LFS 速度慢、效率低、在线(与离线的 Git 不同)且邪恶。请阅读我在eRCaGuy_dotfiles 存储库中的完整咆哮。
git lfs
基本用户如何使用git lfs fetch
这涵盖了以下问题:“ 、git lfs fetch --all
、git 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)
因此,检查文件的一般推荐工作流程可能如下所示:git
git 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)
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。默认参考文献
如果没有给出引用作为参数,则使用当前签出的引用。此外,如果启用,还包括最近更改的引用和提交。有关详细信息,请参阅“最近更改”。
请注意,“当前签出的引用”指的是您当前签出的分支或提交。
git lfs fetch --all
虽然git lfs fetch
仅获取当前签出分支或提交的内容,但默认情况下,git lfs fetch --all
会签出所有远程分支的所有内容。在一个巨大的企业单一存储库上,这意味着git lfs fetch
可能会获取20 GB的数据,而git lfs fetch --all
可能会获取1000 GB的数据。在这种情况下,请勿包括,--all
除非:
git checkout
运行小时,这会浪费您工作日的时间。欲了解更多信息。关于这一点,请参阅:
git
从互联网下载文件?详细了解git fetch
vs git pull
”的部分,我在其中比较和对比了常规git
vs的在线部分git lfs
。来自git lfs fetch --help
(强调):
* --all
:下载由作为参数提供的引用可访问的任何提交引用的所有对象。如果未提供任何引用,则将获取所有引用。这主要用于备份和迁移目的。不能与
--recent
或--include
/组合--exclude
。忽略任何全局配置的包含和排除路径以确保下载所有对象。
git lfs pull
就像是andgit pull
的组合一样,是and的组合。git fetch
git merge
git lfs pull
git lfs fetch
git lfs checkout
来自git lfs pull --help
(强调):
git lfs pull [options] [<remote>]
下载当前签出的引用的 Git LFS 对象,并根据需要使用下载的内容更新工作副本。
这相当于运行以下 2 个命令:
Run Code Online (Sandbox Code Playgroud)git lfs fetch [options] [<remote>] git lfs checkout
所以,这就引出了一个问题:“它git lfs checkout
做什么?”:
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)
。
它提供了一些例子。前任:
例子
检查所有丢失的文件或占位符:
Run Code Online (Sandbox Code Playgroud)$ git lfs checkout
签出几个特定的文件:
Run Code Online (Sandbox Code Playgroud)$ git lfs checkout path/to/file1.png path/to.file2.png
git lfs
. 我现在建议不要git lfs
在我们的免费 GitHub 存储库中使用git lfs post-checkout
在失败后恢复钩子git checkout
- 剧透:由于磁盘空间不足,我git lfs checkout
在 3 小时内下载 27 GB 时,完成率达到 97%,一直失败。find
- 请参阅末尾附近的示例,标题为“(找出要添加到git lfs
下一个的文件扩展名)”。git lfs
信息:
归档时间: |
|
查看次数: |
14561 次 |
最近记录: |