Delete and completely remove the commit from git history

后端 未结 2 659
长情又很酷
长情又很酷 2021-01-06 17:54

I have a commits in my git history

1.commit 4930da17d8dd23d650ed38435d8b421816a0c451
  Date:   Sat Dec 5 14:34:18 2015 +0530

2.commit e1ebbbb599ee20ebec3ca9         


        
2条回答
  •  情深已故
    2021-01-06 18:31

    You can interactively rewrite history with git rebase -i:

    git rebase HEAD~6 -i 
    

    Will open your editor and allow you to either squash multiple commits into one, or completely remove them from history (by deleting the line for those commits in your editor.) The ~6 means rewrite the last 6 commits, the -i means do it interactively. In your case, you'll want to remove the lines that say "pick 1c4a11a" and "pick b4ab3c".

    Note that the most recent commit in the editor that gets launched is the last line, not the first one, and since you're rewriting history and you've already pushed, you'll also have to "git push --force", not just "git push" in order to send your changes upstream.

提交回复
热议问题