How to go back to previous version in git

前端 未结 2 659
悲哀的现实
悲哀的现实 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:59

    I'd advise against pushing with --force an alternative history. Anyone who already pulled your changes will have a completely screwed history to deal with when pulling new stuff.

    A far safer option is to simply do

    git revert HEAD~1 
    git push origin master
    

    git revert will record a new commit that cancels all of the effects of the previous one

提交回复
热议问题