git 删除推送的提交并删除历史条目
git delete pushed commit and remove history entry
我已将一些更改推送到存储库。
我想从存储库中删除最后一次提交并永久删除历史条目。
我该怎么做?
尝试:
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
。如果这样做,但它会覆盖其他人的更改。如果不是 - 不更改历史就无法完成。
我已将一些更改推送到存储库。
我想从存储库中删除最后一次提交并永久删除历史条目。
我该怎么做?
尝试:
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
。如果这样做,但它会覆盖其他人的更改。如果不是 - 不更改历史就无法完成。