Remove local commit completely from tree

亡梦爱人 提交于 2019-12-31 07:01:27

问题


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:


回答1:


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 :)



来源:https://stackoverflow.com/questions/27984814/remove-local-commit-completely-from-tree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!