Delete a specific commit knowing commit id

落花浮王杯 提交于 2020-02-22 08:01:25

问题


Lets say i have a repo (git version 1.7.1) that contains following commits

A -> B -> C -> D ->E and my HEAD is on E. Now i want to delete C while keeping everything same like A -> B -> D -> E .

Can you help me how to do it?


回答1:


You can do this with git rebase -i B. Note however, that D and E will be rewritten (get different commit SHAs), so the result will be A -> B -> D' -> E'. The content of E' should be equivalent to E (minus the changes that had been made in C which you are now discarding), but the ID will differ. This is why you find warnings everywhere about rebasing commits that have already been pushed and potentially may be used by others as the basis for new work. You're rewriting history, which will cause confusion in other repositories unless they are expecting it. However, if this is a private repository, or you haven't pushed yet, you should be fine rearranging commits.



来源:https://stackoverflow.com/questions/12819172/delete-a-specific-commit-knowing-commit-id

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