Undoing a 'git push'

前端 未结 12 1101
遥遥无期
遥遥无期 2020-11-22 13:45

Here\'s what I did on my supposed-to-be-stable branch...

% git rebase master
First, rewinding head to repla         


        
12条回答
  •  一生所求
    2020-11-22 13:57

    You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.

    Then you need to 'force' push the old reference.

    git push -f origin last_known_good_commit:branch_name
    

    or in your case

    git push -f origin cc4b63bebb6:alpha-0.3.0
    

    You may have receive.denyNonFastForwards set on the remote repository. If this is the case, then you will get an error which includes the phrase [remote rejected].

    In this scenario, you will have to delete and recreate the branch.

    git push origin :alpha-0.3.0
    git push origin cc4b63bebb6:refs/heads/alpha-0.3.0
    

    If this doesn't work - perhaps because you have receive.denyDeletes set, then you have to have direct access to the repository. In the remote repository, you then have to do something like the following plumbing command.

    git update-ref refs/heads/alpha-0.3.0 cc4b63bebb6 83c9191dea8
    

提交回复
热议问题