git 删除推送提交并删除历史记录条目



我已经将一些更改推送到存储库。

我想从存储库中删除最后一次提交并永久删除历史记录条目。

我该怎么做?

尝试:

git checkout <branch> // replace branch with a name of the branch you worked on
git reset --hard HEAD~1 // this command removes the latest commit
git push --force-with-lease origin <branch> // push the changes to the remote

如果在执行上述操作时没有人修改遥控器,您的推送将被接受,否则可能会被拒绝。进一步的步骤取决于您是否可以使用 -f 而不是 --force-with-lease 。如果是这样,请这样做,但它会覆盖其他更改。如果没有 - 如果不更改历史记录就无法完成。

最新更新