与上游同步fork:git fetch + git checkout + git merge vs. git checkout + git pull
Github-Help:同步叉上的文档显示了三个使我的GitHub fork与上游存储库保持同步的命令.
The documentation at Github-Help: Syncing a Fork shows three commands to keep my GitHub fork in sync with the upstream repo.
git fetch upstream
git checkout master
git merge upstream/master
我可以使用以下两个命令代替上面的三个命令吗?
Can I use the following two commands instead of the above three?
git checkout master
git pull upstream/master
两组命令是否等效,或者它们之间有区别?
Are the two sets of commands equivalent, or are there differences between them?
这些命令集不相同.
git pull
分为两个命令:
git fetch
git merge
问题在于,git fetch需要一个远程引用,而git merge需要一个跟踪引用,这就是Github帮助页面具有以下原因的原因:
The problem is, that git fetch requires a remote reference, while git merge requires a tracking reference, this is why the Github help page has:
git fetch upstream
但是有
git merge upstream/master
merge命令将使用upstream/master
分支并将其合并到当前已签出的分支(在本例中为"master").但是fetch命令在分支上不起作用,它需要一个远程,所以当您尝试:
The merge command will take the upstream/master
branch and merge it into the currently checked out branch (in this case 'master'). But the fetch command doesn't work on a branch, it requires a remote, so when you try:
git pull upstream/master
Git将其拆分为:
git fetch upstream/master
git merge upstream/master
在获取时将失败:
$ git pull upstream/master
fatal: 'upstream/master' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.