在 git 子树拉取之前是否需要 git 获取?

Is a git fetch necessary before git subtree pull?

我参考了以下文章:git subtree blog entry

其中列出了以下命令:

git remote add -f tpope-vim-surround https://bitbucket.org/vim-plugins-mirror/vim-surround.git
git subtree add --prefix .vim/bundle/tpope-vim-surround tpope-vim-surround master --squash
git fetch tpope-vim-surround master
git subtree pull --prefix .vim/bundle/tpope-vim-surround tpope-vim-surround master --squash

我的问题是:

what is the need for the git fetch tpope-vim-surround master?
Is it not redundant with the git pull listed next line below?

我相信它最近被修复了,但是旧版本的 git subtree 需要一个具有正确名称的分支才能远程获取它,否则它会失败 "foo does not refer to a commit."

所以可能是为了兼容。

git pull 实际上是 2 个命令的别名:git fetch && git merge 所以如果你是 运行 git pull 你实际上也在做 pull fetch。

Is it not redundant with the git pull listed next line below?

fetch 有什么作用?

为了理解 fetch,让我稍微解释一下 git.
场景之外发生的事情 Git 将其内容存储在 .git 文件夹中。让我们将其视为 git 内部文件系统。

当您执行 git fetch 时,它实际上更新了内部 git 文件系统(更准确地说是打包和索引文件)。 fetch 不会 更新您的工作目录,直到您 merge 对所需分支的更改

deos git pull 做什么?

正如关于 fetch 的解释,git pull 实际上是 2 个命令的别名:git fetch && git merge 所以每次执行 git pull 时,你都会更新 git 内部文件系统 + 将这些更改合并到所需的分支(在大多数情况下是您当前的分支)


所以回答你的问题:

Is it not redundant with the git pull listed next line below?

答案是第一次提取是多余的而不是第二次提取。