Remove local commit completely from tree

2020-05-03 10:43发布

I have 5 local unpushed commits and I want to delete commit #3 from the tree, so parent of commit #4 would point to commit #2

How would I do that?

An image describing what I mean:

http://i.imgur.com/PE35Lxm.png

1条回答
姐就是有狂的资本
2楼-- · 2020-05-03 11:12

you can use git rebase -i :

git rebase -i HEAD~5

allows you to interactively choose which of the last (5 in this case) commits you wish to use, edit, squash,...

You will get a file to edit; like this:

pick a58f195 commit 1
pick abe6821 commit 2
pick f74035d commit 3
pick 3f171df commit 4
pick afa24a9 commit 5

in which you will just delete the line pointing to the commit you don't want anymore.. Note that you can do much more with the interactive rebase :)

查看更多
登录 后发表回答