How to pull after a forced git push?

后端 未结 4 599
傲寒
傲寒 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 16:58

    I came across a slightly modified version of this scenario. Here's what I did:

    Initial condition

    A--->B--->C--->D--->E
                        |
                 local-1/master
    
    A--->B--->C--->D--->E
                        |
                  origin/master
    
    A--->B--->C--->D--->E
                        |
                 local-2/master
    

    Squash and force push

    A--->B--->CDE
               |
        local-1/master
    
    A--->B--->CDE
               |
         origin/master
    
    A--->B--->C--->D--->E
                        |
                 local-2/master
    

    Sync changes on local-2/master

    $ git reset --soft B
    
    
        A--->B---> (local uncommitted changes)
             |
      local-2/master
    
    
    $ git stash save "backup"
    
    
        A--->B
             |
      local-2/master
    
    $ git pull origin master
    
    
        A--->B--->CDE
                   |
            local-2/master
    

提交回复
热议问题