Git版本回退操作

  • 通过“git reset --hard CommitID”命令回退到指定 CommitID 的版本,如下示例命令:
git reset --hard 8c38ccaed0c6a7e55aa17e8c730f0f3a9a79ae76

注:“git reset --hard”是强制回退到上一个版本或特定版本,此操作不可逆,在使用之前请慎重考虑清楚。

  • 回退到指定提交
git revert [CommitID]

执行完成回退操作后,执行强制推送到远程仓库,以更新当前远程仓库版本为实际回退的版本,命令如下:

git push origin HEAD --force

注:在执行强制推送命令时需要开通 “ForcePush”权限,否则会弹出如下提示:

! [remote rejected] HEAD -> master (TF401027: You need the Git 'ForcePush' permission to perform this action.

权限设定:

Project Settings >> Repos >> Repositories >> 要设定权限的远程仓库 >> Permissions 设定Tag,将“Force push (rewrite history, delete branches and tags)”权限设定为“Allow

猜你喜欢

转载自blog.csdn.net/LZD_jay/article/details/129178952