[英]What is the difference between `git lfs fetch`, `git lfs fetch --all`, and `git lfs pull`?
盡管使用git
多年,我發現git lfs
( git Large File Storage ) 使用起來相當混亂,即使是在非常基礎的層面上也是如此。 有人可以解釋這三個命令之間的區別嗎?:
git lfs fetch
git lfs fetch --all
git lfs pull
有關的:
經過大量研究並找出幫助頁面的位置后,我得出以下結論:
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
# 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
因此,檢查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
git pull # pull latest git files from the remote, for this branch
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
git lfs fetch
從git lfs fetch --help
(強調添加):
從指定的遠程下載給定 refs 的 Git LFS 對象。 如果您不指定會發生什么,請參閱“默認遠程”和“默認參考”。
這不會更新工作副本。
因此,這就像執行git fetch
(它將遠程內容獲取到本地存儲的遠程跟蹤隱藏分支),除了它是針對git lfs
控制的文件。
我相信它會將git lfs
文件內容提取到您的.git/lfs
目錄,但不會使用這些文件更新您的活動文件系統(當前簽出的分支)。
從幫助菜單的更下方(添加了重點):
默認遙控器
不帶參數,從默認遠程獲取下載。 默認遠程與
git fetch
相同,即基於您首先跟蹤的遠程分支,否則為origin 。默認參考
如果沒有給出 refs 作為參數,則使用當前簽出的 ref 。 此外,如果啟用,最近更改的引用和提交也包括在內。 有關詳細信息,請參閱“最近的更改”。
請注意,“當前簽出的 ref”是指您當前簽出的分支或提交。
git lfs fetch --all
而git lfs fetch
僅獲取當前簽出分支或提交的內容,默認情況下, git lfs fetch --all
簽出所有遠程分支的所有內容。 在一個巨大的企業單一存儲庫中,這意味着git lfs fetch
可能會獲取20 GB的數據,而git lfs fetch --all
可能會獲取1000 GB的數據。 在這種情況下,請勿包含--all
除非:
從git lfs fetch --help
(強調添加):
* --all
:下載所有可從作為參數提供的 refs 訪問的提交所引用的所有對象。 如果沒有提供 refs,那么所有的 refs 都會被 fetched 。 這主要用於備份和遷移目的。 不能與
--recent
或--include
/--exclude
結合使用。 忽略任何全局配置的包含和排除路徑,以確保下載所有對象。
git lfs pull
就像git pull
是git fetch
和git merge
的組合一樣, git lfs pull
是git lfs fetch
和git lfs checkout
的組合。
從git lfs pull --help
(強調添加):
git lfs pull [options] [<remote>]
為當前簽出的 ref 下載 Git LFS 對象,並在需要時使用下載的內容更新工作副本。
這相當於運行以下 2 個命令:
git lfs fetch [options] [<remote>] git lfs checkout
所以,這就引出了一個問題:“ git lfs checkout
是做什么的?”:
git lfs checkout
此命令將git lfs
文件從您的.git/lfs
目錄復制到您當前已簽出的當前引用(分支或提交)的活動工作樹。
從git lfs checkout --help
:
如果對象數據可用,請嘗試確保工作副本包含當前 ref 的 Git LFS 對象的文件內容。 不下載任何內容; 請參閱
git lfs fetch
。Checkout 掃描當前 ref 以查找所有需要的 LFS 對象,然后如果工作副本中缺少文件,或者包含具有相同 SHA 的占位符指針內容,則寫入真實文件內容,前提是我們在本地有它店鋪。 修改后的文件永遠不會被覆蓋。
可以提供一個或多個
<glob-pattern>
作為參數來限制更新的文件集。 Glob 模式按照gitignore(5)
中描述的格式進行匹配。
它提供了一些例子。 前任:
例子
檢出所有丟失或占位符的文件:
$ git lfs checkout
簽出幾個特定的文件:
$ git lfs checkout path/to/file1.png path/to.file2.png
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.