在本地和远程机器上切换到过去的一个commit

当使用GitLab server的时候,有时候需要将代码切换到过去的一个commit,因为我把当前的commit搞得一团糟。

在本地开发机器上,用这个命令切换

git reset --hard 05a0753bd3e24922dd46bb6a04dc93dda9a9ec9f

然后push到GitLab server上,这是不行的,即便我用了--force选项。

remote: error: denying non-fast-forward refs/heads/develop (you should pull first)

最简单的方法就是先删除远程的branch,然后push本地的branch到GitLab server。

git push origin :develop
git push origin develop

还有一种方法,更简单,就是使用-f参数push

git  push -f


你可能感兴趣的:(git)