Git merge conflict after git change - "Your branch and" source / master "diverged"

Here's what's going on:

  • After a recent commit for the remote master, I am making a small minor change in my local repo
  • I add git commit --amend

    and leave the same commit message as HEAD
  • I am trying to push a repo to master git push

And now I get

On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean

      

I want to understand:

  • Why is this happening?
  • What can I do to prevent this?
  • How to reconcile master with local after git change?
+8


source to share


1 answer


You modified an existing push commit by creating your own version (as its content changed)

 --x---Y (master: that is the X amended)
    \
     --X (origin/master)

      

This is why you have 1 and 1 different commits between master and boss / master

What can I do to prevent this?



Do not "modify" existing push on commit (local only, but not yet pushed)

How to reconcile master with local after git change?

Just rebase on top of the original / master, then press

git rebase origin/master

 --x--X---Y' (master)
      |
(origin/master)

git push

 --x--X---Y' (master, origin/master)

      

+9


source







All Articles