Git 说本地分支在从远程拉取后领先于远程

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

Git says local branch is ahead of remote after having pulled from remote

gitcommitgit-pull

提问by Alfonso

I'm sorry if the title isn't clear, but this is a weird problem.

如果标题不清楚,我很抱歉,但这是一个奇怪的问题。

I git checkoutto my "stage" branch and git pullto get my partner's latest changes (which he pushed last night to the "stage" branch on the remote repository), and sure enough, they merge to my local "stage" branch. git log <branch>shows five commits he performed last night.

git checkout到我的“stage”分支并git pull获取我合作伙伴的最新更改(他昨晚将其推送到远程存储库的“stage”分支),果然,它们合并到我本地的“stage”分支。git log <branch>显示他昨晚执行的五次提交。

I then switch over to the master branch to pull that from the repo because he told me he merged those changes to the master branch after testing them. But when I git checkout stageto get back to my "stage" branch it says I'm ahead of the remote branch by 5 commits. I git log origin/stageand it shows none of the five commits I just pulled from that repository (the only remote repository on this project). git log stageshows the five commits on my local "stage" branch, so I'm at a loss at how the remote branch could have gone back in time immediately after serving me my partner's latest commits.

然后我切换到 master 分支从 repo 中提取它,因为他告诉我他在测试后将这些更改合并到 master 分支。但是当我git checkout stage回到我的“阶段”分支时,它说我领先于远程分支 5 次提交。我git log origin/stage并且它没有显示我刚刚从该存储库(该项目中唯一的远程存储库)中提取的五个提交中的任何一个。git log stage显示了我本地“阶段”分支上的五个提交,所以我不知道远程分支如何在为我提供合作伙伴的最新提交后立即回到过去。

I'm pretty new at this, so I'll appreciate your patience with me, as I'm still trying to grasp DCVSs and there's a good chance I'm simply misunderstanding something really basic.

我对此很陌生,所以我会感谢您对我的耐心,因为我仍在努力掌握 DCVS,而且很有可能我只是误解了一些非常基本的东西。

采纳答案by J-16 SDiZ

Try this command:

试试这个命令:

git log origin/stage..stage

This show you what you are ahead of the remote. Do a git rebase origin/stage/ git pushas appropriate.

这向您展示了您领先于遥控器的能力。适当地做一个git rebase origin/stage/ git push

If it doesn't help, see this question : 'git pull origin mybranch' leaves local mybranch N commits ahead of origin. Why?

如果它没有帮助,请参阅此问题:“git pull origin mybranch”使本地 mybranch N 提交超过原点。为什么?