Git says local branch is behind remote branch, but it's not

前端 未结 4 1286
时光取名叫无心
时光取名叫无心 2020-12-12 12:14

Scenario:

  1. I make a new branch
  2. hack on it
  3. commit it
  4. push it
  5. hack on it some more
  6. commit again
相关标签:
4条回答
  • 2020-12-12 12:30

    To diagnose it, follow this answer.

    But to fix it, knowing you are the only one changing it, do:
    1 - backup your project (I did only the files on git, ./src folder)
    2 - git pull
    3 - restore you backup over the many "messed" files (with merge indicators)

    I tried git pull -s recursive -X ours but didnt work the way I wanted, it could be an option tho, but backup first!!!

    Make sure the differences/changes (at git gui) are none. This is my case, there is nothing to merge at all, but github keeps saying I should merge...

    0 讨论(0)
  • 2020-12-12 12:39

    The solution is very simple and worked for me.

    Try this :

    git pull --rebase <url>
    

    then

    git push -u origin master
    
    0 讨论(0)
  • 2020-12-12 12:39

    This happened to me when I was trying to push the develop branch (I am using git flow). Someone had push updates to master. to fix it I did:

    git co master
    git pull
    

    Which fetched those changes. Then,

    git co develop
    git pull
    

    Which didn't do anything. I think the develop branch already pushed despite the error message. Everything is up to date now and no errors.

    0 讨论(0)
  • 2020-12-12 12:46

    You probably did some history rewriting? Your local branch diverged from the one on the server. Run this command to get a better understanding of what happened:

    gitk HEAD @{u}
    

    I would strongly recommend you try to understand where this error is coming from. To fix it, simply run:

    git push -f
    

    The -f makes this a “forced push” and overwrites the branch on the server. That is very dangerous when you are working in team. But since you are on your own and sure that your local state is correct this should be fine. You risk losing commit history if that is not the case.

    0 讨论(0)
提交回复
热议问题