git - 与 git fetch 和 git pull 的混淆

标签 git

我正在经历git scm book并阅读 this page 上的 pull 部分。它说:

While the git fetch command will fetch down all the changes on the server that you don’t have yet, it will not modify your working directory at all. It will simply get the data for you and let you merge it yourself.

我已经使用了“git fetch上游”,它确实将远程分支中存在的所有更改 merge 到我的本地分支,根据我的说法,这也更新了工作目录。但这与上面的说法相矛盾。

我很困惑,无法理解它。有人可以解释一下吗?

我已经浏览过标记为重复的链接。我可能很愚蠢,但我没有从这些答案中得到任何清晰的上述陈述。请帮忙。

更新

这是我运行的命令及其输出:

bash-3.2$ git fetch upstream
remote: Counting objects: 108, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 108 (delta 77), reused 77 (delta 77), pack-reused 23
Receiving objects: 100% (108/108), 25.92 KiB | 0 bytes/s, done.
Resolving deltas: 100% (79/79), completed with 31 local objects.
From <git-repo-url>
   a82339d..9844eeb  master -> upstream/master
   802bae5..6c84bfb  <some-branch> -> upstream/<some-branch>

最佳答案

I have used 'git fetch upstream' and it does merge all the changes existing in the remote branch to my local branch, which according to me updates the working directory as well. But then it contradicts the above statement.

git fetch 不会更新您的本地分支或工作目录。

您可能认为它会更新本地分支,给定这样的行,

   a82339d..9844eeb  master -> upstream/master

但是根据Output section in the git-fetch manual ,这意味着

  • master 是从中获取的远程存储库中的“ref”(分支是一种 ref)的名称,并且
  • upstream/master 是本地存储库中正在更新的引用的名称。

请注意,本地存储库中的分支 master 未更新

关于git - 与 git fetch 和 git pull 的混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42132046/

相关文章:

linux - 使用 git grep 时自动换行

git - 获取特定用户修改特定文件的提交列表

java - 为什么我的 R 文件丢失?在一个全新的项目上。

git instaweb 给出 403 Forbidden - 找不到项目

android - 如何比较 Android Studio 中的两个 Git 分支?

每个文件的 Git 贡献者

git - 仅构建已推送到的 Git 分支

java - 如何从 GitHub 存储库中删除不正确的路径名?

git - 让 git pull --rebase 保留 merge 提交

git - 仅使用 git 在当前目录中添加修改过的文件?