19

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 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.

Alfonso
  • 2,166
  • 3
  • 16
  • 15

2 Answers2

17

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?

Community
  • 1
  • 1
J-16 SDiZ
  • 26,473
  • 4
  • 65
  • 84
  • OK. So that showed me the five commit difference between my local stage branch and the remote stage branch. But I’m confused as to how those commits (which were performed by someone else on a separate location) managed to merge onto my local stage branch and then disappear from the remote stage branch. – Alfonso Oct 29 '10 at 14:37
  • 5
    see the linked question. You should do a `git pull` (no parameter) or `git pull origin`, *BUT NOT* `git pull :` if you have setup correctly. – J-16 SDiZ Oct 29 '10 at 14:39
  • Oh, sorry. For some reason all I saw in your answer was Try this command, the command and nothing else. – Alfonso Oct 29 '10 at 14:41
  • 4
    `git pull origin` reported “Already up-to-date.” yet did fix the “You’re ahead…” message, so thanks a lot! On the other hand, why does `git pull origin ` make the above problem happen? – Alfonso Oct 29 '10 at 14:48
  • 4
    `git pull origin ` updates the `FETCH_HEAD` tag, but not the `origin/*` branch. – J-16 SDiZ Nov 01 '10 at 01:53
  • I had a similar problem. It said I was 4 commits ahead. Even though the log showed only one commit ahead. I did `git diff asdf jkl` (where asdf is the commit that matches the latest commit on origin, and jkl is the newer, mystery commit) and there were no differences at all, apparently. So I did `git reset --hard asdf`, and the problem appears to be solved. – Buttle Butkus May 05 '16 at 07:40
0

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.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40