git pull origin master不更新origin / master? [英] git pull origin master does not update origin/master?

查看:970
本文介绍了git pull origin master不更新origin / master?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档, git pull 执行 git fetch ,然后执行git merge,但是在这种情况下,执行 git pull origin master 应该执行一个 git获取原始大师权利?但是,它似乎并没有这样做。这是一个例子。



假设我的远程原点主(在我的情况下是GitHub)有以下历史记录:

  commit 1111111:我的第一个提交
提交2222222:从别人提交

我只在本地进行了第一次提交,如下所示

  git checkout master 
git log --pretty = format:'%h'-n 1
1111111

git checkout origin / master
git log --pretty = format:'%h' -n 1
1111111

从这里开始,我会看看结果如下:

$ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $格式:'%h'-n 1
2222222

git checkout origin / master
git log --pretty = format:'%h'-n 1
1111111

可以看出,拉实际上用新提交更新了我的主分支)从远程起源,但我的L. ocal origin / master仍然是它的原点。强制我执行以下操作:

  git fetch origin master 

git checkout origin / master
git log --pretty = format:'%h'-n 1
2222222

这是正确的行为为git拉或可能我有一些配置错过?我查看了git pull man page,但没有看到任何暗示,但我可能错过了它。

有点奇怪,但如果你使用 git pull [remote]< refspec> ,它实际上不会更新远程参考。如果你以某种方式思考它是有道理的:因为你指定了一个特定的引用来获取它,所以它不必查找关于你的远程分支的任何东西,所以它本质上不知道它是什么远程分支应该更新。它当然可以弄明白,如果它最终得到修复,我也不会感到惊讶,但那是现有的行为。 (邮件列表上可能有消息 - 我不知道。)



不过,您可以轻松解决此问题。如果你使用 git pull origin / master ,由于你要通过远程分支指定要获取的内容,它应该更新该远程分支。如果你是在你的主分支上(或者任何其他的分支跟踪origin / master),你可以做 git pull 并让它填写默认值,将更新远程分支。



这在 git-pull 手册页中有记录,在EXAMPLES下最简洁,但也别处。相关部分:


将远程分支合并到当前分支中:

  $ git pull origin next 

这会留下下一份副本暂时存放在FETCH_HEAD中,但不更新任何远程跟踪分支。使用远程追踪分支,可以通过调用fetch和merge来完成相同的操作:

  $ git fetch origin 
$ git merge origin / next



According to the documentation, git pull performs a git fetch then a git merge, however in that case performing git pull origin master should perform a git fetch origin master right? However, it does not appear to be doing so. Here is an example.

Supposed my remote origin master (on GitHub in my case) has the following history:

commit 1111111 : my first commit
commit 2222222 : a commit from someone else

and I only have my first commit locally as doing following shows

git checkout master
git log --pretty=format:'%h' -n 1
1111111

git checkout origin/master
git log --pretty=format:'%h' -n 1
1111111

From here I do my pull and look at the results as follows:

git checkout master
git pull origin master

git log --pretty=format:'%h' -n 1
2222222

git checkout origin/master
git log --pretty=format:'%h' -n 1
1111111

As can be seen, the pull did in fact update my master branch with the new commit(s) from the remote origin, but my local origin/master is still where it was. Forcing me to do the following

git fetch origin master

git checkout origin/master
git log --pretty=format:'%h' -n 1
2222222

Is this correct behavior for git pull or might I have something miss configured? I looked through the git pull man page and didn't see anything that suggested this but I may have missed it.

解决方案

It's a bit weird, but if you use git pull [remote] <refspec> it actually doesn't update the remote refs. It sort of makes sense if you think about it a certain way: since you're specifying a specific ref to fetch, it doesn't have to look up anything about your remote branches, so it doesn't inherently know what remote branch it should update. It of course could figure it out, and I wouldn't be surprised if it gets fixed eventually, but that's the existing behavior. (There may be messages on the mailing list about it - I don't know.)

You can easily work around it, though. If you use git pull origin/master, since you're specifying what to fetch via a remote branch, it should update that remote branch. And if you're on your master branch anyway (or any other branch tracking origin/master), you can just do git pull and let it fill in the defaults, and it will update remote branches.

This is documented in the git-pull man page, most concisely under EXAMPLES but also elsewhere. The relevant part:

Merge into the current branch the remote branch next:

$ git pull origin next

This leaves a copy of next temporarily in FETCH_HEAD, but does not update any remote-tracking branches. Using remote-tracking branches, the same can be done by invoking fetch and merge:

$ git fetch origin
$ git merge origin/next

这篇关于git pull origin master不更新origin / master?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆