git - 如何使用 `git merge` 实现与 `git pull` 相同的结果?

标签 git

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 fetchgit 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/

相关文章:

windows - Windows 上的 Git : What do the crlf settings mean?

git - 为什么我的 Git 存储库比工作目录大很多?

Git Flow Hotfix - 同行评审并 merge 到远程 master & develop

windows - Git (Windows) - 无法在克隆时创建文件。作为 super 用户工作

git - 如何检索在 commit-msg Hook 中生成的 git commit 的 sha?

ruby-on-rails - Git 推送到 github : failed to read object 失败

windows - 如何将 bash 脚本输出通过管道传输到 Windows 上的文件

windows - 适用于 Windows 的 Msysgit - Cheetah 插件未显示?

linux - Git、Windows、Linux 和 NTFS : "index file open failed"

xcode - 如何在不授予命令行访问权限的情况下授予 friend 访问 git 存储库的权限?