How to pull after a forced git push?

后端 未结 4 596
傲寒
傲寒 2021-01-30 16:34

Suppose I pull changes from a git repo. Then the author of the repo force pushes to the central repo. Now I can\'t pull since the history is rewritten.

How can I pull th

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-30 17:00

    if have NO local commits, this will recover your checkout from a force push. You will be up to date with the remote branch, and can commit your local work later.

    git fetch
    git stash
    git reset --hard origin/master # destroys your work
    git stash pop # restores your work as local changes
    git mergetool # fix any conflicts
    

    At this point you have your local changes as they were before. Your checkout is up to date with all the changes on master, or whatever branch you are working from.

提交回复
热议问题