Black Sheep Code

Delete a range of commits

Published:

Say you've got a git tree that looks like this

A --- B --- C --- D --- E --- F

And you want to delete commits B, C, D, E.

You could do a

git rebase -i HEAD~6

and mark each commit to be deleted, but this is pretty cumbersome - and it won't work programmatically.

In this case the --onto option for git rebase is useful:

git rebase --onto B^ E

will do the trick.



Questions? Comments? Criticisms? Get in the comments! 👇

Spotted an error? Edit this page with Github