git pull origin master 不更新 origin/master?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8689054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git pull origin master does not update origin/master?
提问by Kenneth Baltrinic
According to the documentation, git pullperforms a git fetchthen a git merge, however in that case performing git pull origin mastershould perform a git fetch origin masterright? However, it does not appear to be doing so. Here is an example.
根据文档,git pull执行git fetch然后执行 git merge,但是在这种情况下执行git pull origin master应该执行git fetch origin master对吗?然而,它似乎并没有这样做。这是一个例子。
Supposed my remote origin master (on GitHub in my case) has the following history:
假设我的远程源主机(在我的情况下在 GitHub 上)具有以下历史记录:
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
可以看出,pull 实际上确实用来自远程源的新提交更新了我的主分支,但我的本地源/主仍然在原处。强迫我做以下事情
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.
这是 git pull 的正确行为还是我配置了一些错误?我浏览了 git pull 手册页,没有看到任何暗示这一点的内容,但我可能错过了。
采纳答案by Cascabel
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.)
这有点奇怪,但如果你使用git pull [remote] <refspec>
它实际上不会更新远程引用。如果您以某种方式考虑它,这有点有意义:由于您指定了要获取的特定 ref,因此它不必查找有关远程分支的任何信息,因此它本质上并不知道它是哪个远程分支应该更新。它当然可以弄清楚,如果它最终得到修复,我不会感到惊讶,但这是现有的行为。(邮件列表上可能有关于它的消息 - 我不知道。)
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.
不过,您可以轻松解决它。如果您使用git pull origin/master
,因为您指定通过远程分支获取什么,它应该更新该远程分支。如果你无论如何都在你的主分支上(或任何其他跟踪源/主的分支),你可以这样做git pull
并让它填写默认值,它会更新远程分支。
This is documented in the git-pull
man page, most concisely under EXAMPLES but also elsewhere. The relevant part:
这记录在git-pull
手册页中,最简洁地在示例下,但也在其他地方。相关部分:
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 next
这会在 FETCH_HEAD 中临时保留 next 的副本,但不会更新任何远程跟踪分支。使用远程跟踪分支,同样可以通过调用 fetch 和 merge 来完成:
$ git fetch origin $ git merge origin/next
回答by Nishant Ranjan
it seems you have forked the repository and your forked branch is not updated with the latest code
您似乎已经分叉了存储库,并且您的分叉分支未使用最新代码进行更新
回答by John Drinane
I had this issue also - where I ran "git pull" while on a branch then checked the log and it had not been updated. Confused I actually read the output from the git pull and it speciically mentions you need to tell git where to merge and this is done by a command along the lines of "git pull [remote] [local branch]" ie for me it was "git pull origin newfeature1".
我也有这个问题 - 我在一个分支上运行“git pull”然后检查日志并且它没有更新。困惑我实际上读取了 git pull 的输出,它特别提到你需要告诉 git 在哪里合并,这是通过“git pull [remote] [local branch]”这样的命令来完成的,即对我来说是“ git pull origin newfeature1"。
First command attempt with issue:
第一个有问题的命令尝试:
Z:\Abusers\jd\repo1> git pull
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 16 (delta 7), reused 15 (delta 7), pack-reused 1
Unpacking objects: 100% (16/16), done.
From github.abc.com:group1/repo1
06aefba..e5ed6ee develop -> origin/develop
af689cb..b8667a6 newfeature1-> origin/newfeature1
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> newfeature1
Working command:
工作命令:
Z:\Abusers\jd\repo1> git pull origin newfeature1
From github.abc.com:group1/repo1
* branch newfeature1-> FETCH_HEAD
Updating af689cb..b8667a6
Fast-forward
.../file1.py | 2 +-
abc/yes1/cool1.a | Bin 0 -> 106329 bytes
.../abc.py | 7 ++++---
3 files changed, 5 insertions(+), 4 deletions(-)
create mode 100644 abc/yes1/cool1.a