How to go back to previous version in git

前端 未结 2 703
悲哀的现实
悲哀的现实 2021-02-08 08:13

I have a checkout copy of a remote git repository in my workstation. I have accidentally committed a change in my local and pushed to remote. Now I want to remove the last commi

2条回答
  •  不要未来只要你来
    2021-02-08 08:45

    If nobody has yet cloned your updated remote repo, you can:

    git reset --hard HEAD~
    git push --force
    

    That will force the local and remote history to discard the latest commit.
    (Check first with a git fetch that no new commits had been pushed since your incorrect commit)

    If a new history isn't an option, then a git revert is more secure, and will result in a new commit canceling the previous one: you can then push that new commit.

提交回复
热议问题