What is the difference between 'git pull' and 'git fetch'?
上述问题的最佳答案是
"In the simplest terms, git pull does a git fetch followed by git merge or git rebase."
我理解 git fetch && git rebase
字面意思是 git pull
。
但是如何使用git fetch
和git merge
达到相同的结果呢?
这是我的实验:
git fetch && git rebase # correctly replays remote commits in working copy
git fetch && git merge upstream/master # error
merge: upstream/master - not something we can merge
我希望 git merge
能够在当前工作副本中正确重放远程提交 - 这正是 git pull
所做的。
最佳答案
git fetch
此命令将下载远程存储库及其分支的状态,但不会对您的本地副本执行任何操作
git merge branch_to_merge
此命令将 merge 您当前所在分支中的branch_to_merge。您不能只键入不带参数的 git merge,因为 git 会回复:fatal: No commit specified and merge.defaultToUpstream not set
git rebase
这个命令可以让你重写你的分支的历史,并把它放在指定的提交上
关于git - 如何使用 `git merge` 实现与 `git pull` 相同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20116558/