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

前端 未结 4 1295
时光取名叫无心
时光取名叫无心 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条回答
  •  萌比男神i
    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.

提交回复
热议问题