强制删除远程分支提交记录(不留提交痕迹,需谨慎操作!!)

229 阅读1分钟

要删除远端提交,你需要使用 git 的强制推送命令。下面是详细的步骤:
1、首先,使用 git log 命令查看你想要删除的提交的哈希值(commit hash)。

git log

2、然后,使用 git reset 命令将本地仓库回滚到要删除的提交之前的提交。

git reset --hard xxx 对应版本号 //回退到之前指定版本

3、现在,你的本地仓库已经回滚到了要删除的提交之前的状态。要更新远端仓库,你需要使用 git push 命令的强制选项(–force)

git push --force origin your-branch

在push过程中,可能会遇到以下错误信息:

error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500
fatal: expected 'packfile'

原因是git的http.postBuffer缓存空间给少。可通过以下命令查看git配置

git config --global --list

通过以下命令,把http.postBuffer缓存空间设置为500M

git config --global http.postBuffer 524288000

配置生效后,再push一次,成功推送