1

I work on project alone. I had in git log 5 commits. I merged these commits into one

git rebase -i HEAD~5
pick xxxx commit1
squash xxxx commit2
squash xxxx commit3
squash xxxx commit4
squash xxxx commit5

Now I have one commit in git log. Everything is nice. But I have after git status the next message:

Your branch and 'origin/master' have diverged,
# and have 1 and 5 different commits each, respectively.

I have to do git pull but after that I'll rewrite my git log to 5 commits again (I think).

To cut a long story short how can I push local git commits history into origin branch and get rid of the diverged error?

fortegente
  • 1,361
  • 2
  • 11
  • 22
  • 2
    Do you want to squash commits, which are already published? Then check http://stackoverflow.com/questions/8386996/how-can-i-choose-to-overwrite-remote-repository-with-local-commits – Greg Dec 17 '13 at 08:32

2 Answers2

0

You can force your version of the history onto origin:

git push origin master --force

But please be aware that rewriting git history is frowned upon: http://git-scm.com/book/ch3-6.html#The-Perils-of-Rebasing

mockinterface
  • 14,452
  • 5
  • 28
  • 49
-1

You need to merge origin/master

git merge origin/master
moisesvega
  • 435
  • 1
  • 5
  • 16
  • Will my history commits rewritten again to 5 commits? I want to avoid this. – fortegente Dec 17 '13 at 08:32
  • No actually you are going to update origin, right now you have just updated your local repository after doing the merge then you will be able to do a push into origin – moisesvega Dec 17 '13 at 08:34
  • 1
    This won't do what you say it does, and doesn't help the OP. This doesn't update origin, this first brings back the five commits to local master (exactly what shouldn't happen), and if you then push, that's useless, because that's the history that the OP wants to get rid of. –  Dec 17 '13 at 08:58