## 查看所有commits記錄
$ git log
## gitlab回退到某次commit
$ git reset --hard 3018a546427e1f865524b82b488d6a2721d00759
$ git reset 3018a546427e1f865524b82b488d6a2721d00759
注意:3018a546427e1f865524b82b488d6a2721d00759為commit id
## 強制重新提交到遠程
$ git push -f
git報錯You are not allowed to force push code to a protected branch on this project解決方案
當我們有時候回滾了代碼,想強制push到遠程倉庫的時候,
$ git push origin --force
會報如下錯誤:
You are not allowed to force push code to a protected branch on this project
如果用的是gitlab版本庫,這說明gitlab對倉庫啟用了保護,需要在倉庫中設置一下:
"Settings" -> "Repository" -> scroll down to "Protected branches". -> 找到項目,點擊"Unprotect"按鈕,使項目不受保護。
重新執行如下命令即可:
$ git push origin --force