How to revert last commit and remove it from history?

后端 未结 5 781
花落未央
花落未央 2020-12-12 19:08

I did a commit and reverted with

git revert HEAD^

just git log

➜  git:(master) git log
commit 45a0b1371e4705c4f875141232d7         


        
5条回答
  •  情歌与酒
    2020-12-12 19:50

    If you don't care about the commit, just do:

    git reset --hard HEAD~
    

    to blow away the commit.

    If you want the changes to be in working directory, do:

    git reset HEAD~
    

    Depending on what you have done with git revert, you might have to change the above commands. Revert creates a new commit that reverts the commit you wanted to revert. So there will be two commits. You might have to do HEAD~2 to remove them both.

    Note that, usually, revert is the safer way to, well, revert changes. But here, since you want to remove sensitive data, reset is the best approach.

提交回复
热议问题