为什么 git pull origin master 不起作用,但 git pull 可以?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11433731/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:12:45  来源:igfitidea点击:

Why did a git pull origin master not work, but a git pull did?

gitbranchgit-pull

提问by user1517898

So I ran into a peculiar problem this morning, and I was wondering if the community could help me figure it out. So I've been doing git pull origin masterwhen I want to fetch and merge the projects changes from the remote master copy and bring them to my local master. I've been running into some merging issues lately though, so I did an experiment. I did a git pull origin masterlike always, and got the message that said "Already up-to-date." Then I did a normal git pulland then saw all of my coworkers changes rolling in and merging with my local master branch. Why did a git pull origin master not work, but a git pull did? I wonder how many changes I haven't been seeing because of this quirk I discovered. I've done some research to find out what the differences are but I still haven't found a reason why my repo wasn't being updated properly with a git pull origin master, when I've seen changes being fetched and merged into my branch with that method before. Thoughts?

所以今天早上我遇到了一个奇怪的问题,我想知道社区是否可以帮助我解决这个问题。所以git pull origin master当我想从远程主副本中获取和合并项目更改并将它们带到我的本地主时,我一直在做。不过最近我遇到了一些合并问题,所以我做了一个实验。我git pull origin master像往常一样,收到了“已经是最新的”消息。然后我做了一个正常的git pull然后看到我所有的同事都发生了变化,并与我当地的 master 分支合并。为什么 git pull origin master 不起作用,但 git pull 可以?我想知道由于我发现的这个怪癖,我没有看到多少变化。我已经做了一些研究来找出差异是什么,但是当我看到更改被获取并合并到我的之前用那个方法分支。想法?

Thanks in advance.

提前致谢。

回答by Christopher

It sounds like your local branch isn't tracking what you think it is. Try issuing git remote show originand check the "Local branch configured for 'git pull':" section. git pullwithout specification will default from the "remote" and "merge" configuration of the current branch, per the man page:

听起来您当地的分支机构没有跟踪您的想法。尝试发出git remote show origin并检查“为‘git pull’配置的本地分支:”部分。git pull根据手册页,没有规范将默认来自当前分支的“远程”和“合并”配置:

Default values for and are read from the "remote" and "merge" configuration for the current branch as set by git-branch(1) --track.

和的默认值是从 git-branch(1) --track 设置的当前分支的“远程”和“合并”配置中读取的。

I'd bet you have a different branch configured for tracking than origin/master. It's also possible you're pulling from a different remote. To verify these possibilities, try:

我敢打赌,您配置的跟踪分支与origin/master. 您也可能从不同的遥控器拉。要验证这些可能性,请尝试:

git config branch.master.remote ;# shows you the tracked remote
git config branch.master.merge ;# shows you the tracked upstream branch

These assume your local branch is called master.

这些假设您的本地分支称为master

回答by Manatok

By the sounds of things you are pulling down other branches. Either the other devs are working on another branch or you are in a detached state and no longer on a branch / their branch.

通过事物的声音,您正在拉下其他分支。其他开发人员正在另一个分支上工作,或者您处于分离状态并且不再在分支/他们的分支上。

If you run git branch --allit will show you all of the branches on your project.

如果您运行git branch --all它,它将显示您项目中的所有分支。

To switch back to master just run: git checkout master

要切换回 master 只需运行: git checkout master

Hope this helps

希望这可以帮助