开发者

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

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

I git checkout to my "stage" branch and git pull to 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开发者_如何学Python he performed last night.

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 stage to get back to my "stage" branch it says I’m ahead of the remote branch by 5 commits. I git log origin/stage and it shows none of the five commits I just pulled from that repository (the only remote repository on this project). git log stage shows 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.

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.


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 push as appropriate.

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


I got the similar problem now after the following had happened:

  • My collegue pushed a simple commit
  • I pulled that commit, my tool has marked "Commit merged changed immediately"
  • My collegue decides to do an --amend to change his original commit so that it becomes two different commits instead
  • I pulled that changes, ending up being three commits ahead of origin

My simple solution was to undo these three local commits, running the following command for each commit:

git reset --soft HEAD~1

Then git status tells I am behind origin with two commits, and I can pull those commits as usual.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜