In idea, git pushes the wrong code to the remote warehouse, how to roll back

Posted May 27, 20202 min read

Method 1:idea + git command

As shown in the figure:Red 1 place is the branch that I submitted the wrong, and it was pushed to the remote warehouse(this branch can only be merged with the previous branch after going online. Found it now, regret it ~);
Red 2 place is the original master code that I want to roll back

step1:copy target revision number

Copy Revision Number copies the revision number to be rolled back; as shown in the figure:


step2:bring up the Reset Head popup;

Project name-> right click-> git-> Repository-> Reset HEAD ...
As shown:

Out of the box:"Reset Head":

step3:Reset Head in Hard mode, using the copy target revision number

(1). Select "Hard" for Reset Type;
(2). Paste the revision number just copied into To Commit;
(3). Select Reset


step4:git push -f force commit

At this time, the code returns to the old version and cannot be submitted, it will conflict; ~ but ~
You can force a commit in the past:git push -f

step5:Finished! Check to confirm

Check:It is already the previous branch version:

step6:Take a towel to wipe your sweat, and then go get a glass of water to drink ~

Method 2:Pure commands

step1:Get revision \ _number For example:92cc728efbxxxx

(git checkout/git status)

step2:git reset --hard 92cc728efbxxxx
step3:git push -f