git force rollback code

Local code rollback && forced to update remote code

If the code has been submitted to the master branch, I made a mistake at this time, and I need to roll back the last local code && force the update of the remote code.
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
We use

git log    //查看已经提交的日志信息以及id

15866...44a9 is my third commit, which is my last commit
ef1c0...a3a6 is my second commit
we use

$ git reset --hard  ef1c0d693f51e85f6c9a5bff7963fa61d4c6a3a6 //表示我们回到此时的代码

insert image description here
insert image description here
At this time, our local code will be different from the remote one && our local version number will be one level lower. If we ignore this, we will re-operate in the local git add. git push, etc., you will find that the command line will call You git pull to pull the code from the new
insert image description here
If we want to force the update to the remote end, we need such a command

git push -f origin master  //强制更新到远端分支

insert image description here
Using the git reset --hard command is to roll back the local code and will not involve changes in the remote code

Guess you like

Origin blog.csdn.net/xiaowanzi_zj/article/details/129224041