- 通过“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”

通过`gitreset--hardCommitID`可以强制回退到指定的Git版本,但需谨慎,因为此操作不可逆。回退后,使用`gitpushoriginHEAD--force`可强制推送更改至远程仓库,但需具备ForcePush权限。若无权限,会遇到推送拒绝。要开启该权限,需在项目设置中允许ForcePush。
1082

被折叠的 条评论
为什么被折叠?



