How to pull after a forced git push?

后端 未结 4 629
傲寒
傲寒 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:07

    If you have not made any changes to the local branch, you could try the following sequence of commands. Please remember this is a crude way to achieve what you are asking for.

    git checkout master
    git pull
    git remote update origin -p
    git branch -D myBranch
    git checkout myBranch
    

    git remote update origin -p is optional.

    If you made a changes and you do not care about the contents of the local branch, you could try this:

    git stash
    git stash drop
    git checkout master
    git pull
    git remote update origin -p
    git branch -D myBranch
    git checkout myBranch
    

    Both the techniques are really long and cumbersome. But get the job done.

提交回复
热议问题