我已经向代码仓库推送了一些更改。
我想从代码仓库中删除最后一次提交,并永久删除历史记录条目。
我该怎么做?
尝试:
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
。如果可以,请执行此操作,但它将覆盖其他人的更改。如果不行 - 则无法在不更改历史记录的情况下完成。