zl程序教程

您现在的位置是:首页 >  其他

当前栏目

git 强制回退到指定版本

2023-02-18 16:31:20 时间

在工作中,有时候,我们需要强制回退到指定位置。命令:

假设现在commit的id是564564f489465465d45ec

需要回退的commit的id是:8f23b7e81331c404cf26

回退命令:

git reset --hard  8f23b7e81331c404cf26

强制提交:

git push -f -u origin master

如果在提交的时候出现如下错误:

 ! [remote rejected]   master -> master (pre-receive hook declined)

error: failed to push some refs to xxxx.如下图:

问题产生原因:因为master是被保护的。

master被保护了,就不允许这种操作了。

解决方案:

登录git(需要有权限的人登录才可以),选择对应的项目,点击【setting】

选择[Protected Branches];

解除[master]的保护即可;

push完代码之后,再把[master]Protect起来即可;

切记:push完代码之后,再把master,protect起来。切记,切记!!