问题
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