Remove a single commit from history

This question already has an answer here:

  • Delete commits from a branch in Git 23 answers

  • To get rid of commit d21971 you could do

    git rebase -i d21971^
    

    It will open your text editor with the list of commit up to the parent of commit d21971 . Just delete the line with commit d21971 , save and quit. It will delete it.

    To make sure you won't lose any commit even if you make an error, you could tag your current branch first. For example:

    git tag safetyTag
    git rebase -i d21971^
    #Decide that you don't like what you just did
    git checkout safetyTag
    git branch -f master
    
    链接地址: http://www.djcxy.com/p/9010.html

    上一篇: 如何在git中撤销提交

    下一篇: 从历史记录中删除单个提交