我正在经历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/