Undoing a 'git push'

前端 未结 12 1004
遥遥无期
遥遥无期 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 14:03

    Scenario 1: If you want to undo the last commit say 8123b7e04b3, below is the command(this worked for me):

    git push origin +8123b7e04b3^:
    

    Output looks like below:

    Total 0 (delta 0), reused 0 (delta 0)
    To https://testlocation/code.git
     + 8123b7e...92bc500 8123b7e04b3^ -> master (forced update)
    

    Additional info: Scenario 2: In some situation, you may want to revert back what you just undo'ed (basically undo the undo) through the previous command, then use the below command:

    git reset --hard 8123b7e04b3
    

    Output:

    HEAD is now at cc6206c Comment_that_was_entered_for_commit
    

    More info here: https://github.com/blog/2019-how-to-undo-almost-anything-with-git

提交回复
热议问题